Skip to content

BQL Language Reference

BQL (Bucket Query Language) is the query language of the Bucket data structure, used for document operations. Queries are written in JSON or BSON format.

Queries are JSON objects that specify conditions for matching documents.

{ "status": "active" }
{ "age": 25 }
{ "verified": true }
{}
OperatorDescriptionExample
$eqEqual to{ "age": { "$eq": 25 } }
$neNot equal to{ "status": { "$ne": "deleted" } }
$gtGreater than{ "age": { "$gt": 18 } }
$gteGreater than or equal{ "price": { "$gte": 10 } }
$ltLess than{ "age": { "$lt": 65 } }
$lteLess than or equal{ "price": { "$lte": 100 } }

Multiple operators on the same field are implicitly combined with AND:

{ "age": { "$gte": 18, "$lt": 65 } }
{ "price": { "$gt": 10, "$lte": 50, "$ne": 25 } }
OperatorDescriptionExample
$inValue in array{ "status": { "$in": ["active", "pending"] } }
$ninValue not in array{ "status": { "$nin": ["deleted", "archived"] } }
$allArray contains all values{ "tags": { "$all": ["urgent", "bug"] } }
$sizeArray has specific length{ "items": { "$size": 3 } }
$elemMatchArray element matches condition{ "scores": { "$elemMatch": { "$gte": 80 } } }

Scalar array: match elements where scores >= 80 AND < 90:

{ "scores": { "$elemMatch": { "$gte": 80, "$lt": 90 } } }

Object array: match an item with product=“xyz” AND score >= 8:

{ "items": { "$elemMatch": { "product": "xyz", "score": { "$gte": 8 } } } }
OperatorDescriptionExample
$existsField exists or not{ "email": { "$exists": true } }

Field must exist:

{ "phone": { "$exists": true } }

Field must not exist:

{ "deletedAt": { "$exists": false } }

Explicit AND of conditions:

{ "$and": [
{ "status": "active" },
{ "age": { "$gte": 18 } }
] }

Multiple fields in the same object are implicitly AND:

{ "status": "active", "age": { "$gte": 18 } }

Match any condition:

{ "$or": [
{ "status": "active" },
{ "status": "pending" }
] }

Negate a condition:

{ "price": { "$not": { "$gt": 100 } } }

Match none of the conditions (equivalent to $not + $or):

{ "$nor": [
{ "status": "deleted" },
{ "status": "archived" }
] }
{
"$and": [
{ "$or": [
{ "status": "active" },
{ "priority": "high" }
] },
{ "age": { "$gte": 18 } }
]
}

Querying for null values:

{ "middleName": { "$eq": null } }
{ "deletedAt": null }
TypeExampleDescription
String"Alice"UTF-8 string
Int322532-bit integer
Int64922337203685477580764-bit integer
Double19.9964-bit floating point
Decimal128"123.456"128-bit decimal
Booleantrue, falseBoolean value
NullnullNull value
DateTimeBSON DateTimeDate and time
TimestampBSON TimestampTimestamp
BinaryBSON BinaryBinary data
ObjectId"6835a1c0e4b0f72a3c000001"12-byte unique identifier (auto-detected from 24-char hex string)
VersionstampBSON Binary (12 bytes)FoundationDB Versionstamp
Array[1, 2, 3]Array of values
Document{ "nested": "value" }Nested document

Use dot notation for nested fields:

{ "user.address.city": "Istanbul" }
{ "metadata.version": { "$gte": 2 } }
{ "status": "active", "age": { "$gt": 18 } }
{ "orderStatus": { "$in": ["shipped", "delivered"] } }
{ "price": { "$gte": 10, "$lte": 100 } }
{ "email": { "$exists": true }, "emailVerified": true }

Find documents with tags containing both “urgent” and “bug”

Section titled “Find documents with tags containing both “urgent” and “bug””
{ "tags": { "$all": ["urgent", "bug"] } }
{
"$or": [
{ "priority": "high", "status": "open" },
{ "dueDate": { "$lt": "2025-01-01" } }
]
}

BQL accepts queries in both JSON and BSON formats. Use the SESSION.ATTRIBUTE command to configure:

  • input_type: json or bson
  • reply_type: json or bson

The query engine enforces strict type matching during predicate evaluation. This behavior is always active and not configurable.

Non-numeric types (STRING, BOOLEAN, DATETIME, etc.) are strictly separated: a type mismatch always evaluates to false. For numeric types (INT32, INT64, DOUBLE, DECIMAL128), lossless numeric widening is supported. An INT32 predicate can match an INT64 value, but a STRING predicate never matches an INT32 value.

INT32 predicate matches INT32 and INT64 values:

{ "age": { "$eq": 25 } }

STRING predicate never matches INT32 values:

{ "age": { "$eq": "25" } }

For the full widening rules, common type resolution, and index-side type enforcement (bucket.index.strict_types), see Strict Types.

  • Decimal128 indexing is not yet supported
  • Full-text search is not supported
  • Geospatial queries are not supported
  • Aggregation pipeline is planned for future releases