Creating a Query Builder
Methods
collection
Set the collection to query.find
Add complex find conditions using LogicalOperator.LogicalOperator.And().
whereField
Quick field condition.WhereClause with all field condition operators.
select
Select specific fields using a builder.selectFields
Quick field selection by name.selectAll
Select all fields.limit
Set result limit.offset
Set result offset.orderBy / sortBy
Set sort order.sortBy is the primary method; orderBy is an alias.
take / skip
Aliases forlimit and offset.
includeHistory
Include all historical versions of records. Default isfalse (returns only latest version).
groupBy
Group results by field. Returns aGroupByQueryBuilder.
joinOne
One-to-one join. Returns a single object or null.JoinBuilder.
joinMany
One-to-many join. Returns an array of objects.JoinBuilder.
Response Type
QueryResponse
Allexecute() calls return a QueryResponse<T>:
limit() and offset(), records contains only the current page while total reflects the full count.
Execution Methods
execute
Execute query and return results.executeUnique
Execute and return the single latest record (sorted by updatedAt/createdAt).executeWithPayment
Execute a query with payment proof for paid reads.getQueryRequest
Get the raw query request object without executing.buildRawQuery
Inspect the raw query structure (useful for debugging).clone
Clone the query builder for reuse.isValid
Check if the query has required components.Aggregation Methods
count
Count matching records.sumBy
Sum a numeric field.avgBy
Average a numeric field.minBy
Get minimum value.maxBy
Get maximum value.distinctBy
Get distinct values.countDistinct
Count distinct values.runAggregate
Run multiple aggregations in a single HTTP round-trip.GroupByQueryBuilder
Returned by.groupBy(field). Groups records by the specified field and applies an aggregation to each group. All methods return Promise<Record<string, T>> where keys are the distinct group values.
Supports nested field paths (e.g., 'user.country').
count
Count records in each group.sumBy
Sum a numeric field within each group.avgBy
Calculate average of a numeric field within each group.maxBy
Find maximum value of a field within each group.minBy
Find minimum value of a field within each group.run
Run multiple aggregations per group in a single HTTP round-trip.Examples
WhereClause / Field Condition Operators
Comparison
String
Array / Set
Boolean
Existence
Network / Security
Special
Date Filtering
There are no date-specific operators. Use comparison operators on ISO 8601 date strings:JoinBuilder
onField
Set join condition using a field. Returns aJoinWhereClause.
.equals(value), .in(values), .greaterThan(value), .lessThan(value), .isNull(), .isNotNull()
Use '$data.fieldname' to reference parent fields in join conditions.
on
Add complex filter conditions for the joined collection.selectFields
Select fields from joined collection.selectAll
Select all fields from joined collection.Nested JOINs
JoinBuilder supports nested joins before calling.build().