Queries
Queries subscribe to filtered lists from a collection. Query signals are array-like and contain document signals for the collection.
Basic Query
In React:
For batch screens that need several subscriptions to become ready together, use
useBatchSub() and close the barrier with a final no-argument call:
useBatchSub() is the public batch subscription API. Legacy query hooks
such as useQuery, useQuery$, useBatchQuery, and useBatchQuery$ are not
part of the object-tree API.
useBatchSub(signal, params, options) is syntax sugar for
useSub(signal, params, { ...options, batch: true, async: false }); the
no-argument useBatchSub() call is syntax sugar for the lower-level
useSub(undefined, undefined, { batch: true }) barrier.
Query Params
Query params use Mongo-style syntax:
When schemas are generated, TypeScript checks query fields and values against the collection schema.
Nested dotted fields are checked when the path is a literal:
Computed keys are allowed for Mongo patterns that are only known at runtime. In that case TypeScript can preserve the query object shape, but it cannot validate the computed field's value against a specific schema field:
Result Signals
Query results behave like collection arrays for reading:
Collection model methods are also available on query result signals when the result points to the same collection:
Top-level query results are array-readable. Array mutators such as push and pop are only typed on actual array fields, because mutating a query result as an array is not a valid database operation.
Query Metadata
Query signals expose metadata as named child signals:
ids contains the ordered document ids for the current query result. extra contains server-provided metadata such as count results when the query returns it.
You can also use method aliases when that reads better in imperative code:
These names are reserved on query signals. If a real document id is ids or extra, access that document through the collection object tree:
Queries vs Aggregations
Use queries for simple filtering and sorting. Use Aggregations for $group, $project, $lookup, $unwind, and other pipeline stages.