Skip to main content

Query Language

Instance search uses MongoDB Query Language (MQL) syntax for filters. The $operator convention is familiar, and fields map directly to your process variables. Stateway translates your filter into safe, parameterized PostgreSQL — MongoDB is not involved.

Request body

{
"definitionKey": "loan-application",
"statusScope": "active",
"filter": { "variables.loan_status": "in_review" },
"sort": { "startedAt": -1 },
"page": { "limit": 50, "cursor": null },
"projection": { "variables.loan_status": 1, "variables.amount": 1 }
}
FieldRequiredDescription
definitionKeyNoRestrict to one process definition. Absent = all definitions
definitionVersionNolatest (default), all, or a specific version number
statusScopeNoactive (default), completed, all, or explicit list. See Status Scope
filterNoMQL filter (see below)
textNoText search. See Text Search
sortNo{ "field": 1 } ascending, { "field": -1 } descending. Default: { "startedAt": -1 }
pageNoCursor-based pagination. See Pagination
projectionNoWhich variable fields to include ({ "variables.field": 1 }). Default: all

Field addressing

PrefixWhat it targetsExamples
variables.<path>Process variable (dot notation for nested fields)variables.loan_status, variables.applicant.email
Bare nameInstance metadata columnstartedAt, endedAt, status, correlationId

Filter syntax

Equality (implicit)

{ "variables.loan_status": "in_review" }

Root-level fields are implicitly ANDed:

{
"variables.loan_status": "in_review",
"variables.amount": { "$gte": 50000 }
}

Comparison operators

{ "variables.amount": { "$gt": 10000, "$lte": 100000 } }
OperatorMeaningValue types
$eqEqual (explicit form)any
$neNot equalany
$gtGreater thannumber, date (ISO 8601)
$gteGreater than or equalnumber, date
$ltLess thannumber, date
$lteLess than or equalnumber, date

List operators

{ "variables.applicant.region": { "$in": ["SP", "RJ", "MG"] } }
OperatorMeaning
$inValue is in the list
$ninValue is not in the list

Existence check

{ "variables.flagged": { "$exists": true } }

Returns instances where the variable key exists (true) or does not exist (false).

String matching

{ "variables.applicant.email": { "$regex": "@company\\.com$", "$options": "i" } }

$options: "i" enables case-insensitive matching.

Boolean logic

{
"$or": [
{ "variables.applicant.region": "SP" },
{ "variables.applicant.region": "RJ" }
]
}
OperatorMeaning
$andAll conditions must match (also implicit at root level)
$orAt least one condition must match
$norNone of the conditions match
$notNegation of a sub-condition

Operators can be nested up to 10 levels deep:

{
"$and": [
{ "variables.loan_status": "in_review" },
{ "$or": [
{ "variables.amount": { "$gte": 50000 } },
{ "variables.priority": "high" }
]}
]
}

Unsupported operators

The following operators return 400:

OperatorReason
$elemMatch, $all, $sizeArray-specific, not applicable to JSONB
$type, $modNot supported
$whereNever supported — executes arbitrary JavaScript

Limits

LimitValue
Filter nesting depth10 levels
Conditions per query50
Page size maximum200
Query timeout5 seconds

All limits return 400 with a descriptive message when exceeded.