Documentation Index
Fetch the complete documentation index at: https://mintlify.com/abejarano/ts-mongo-criteria/llms.txt
Use this file to discover all available pages before exploring further.
Criteria is the central query object in ts-mongo-criteria. It bundles a Filters collection, an Order specification, and optional pagination parameters into a single value that MongoRepository.list() (or your own repository) consumes to build and execute a MongoDB query.
Constructor
The set of filter conditions to apply to the query. Pass
Filters.none() to
retrieve all documents without filtering.The sort specification for the query. Pass
Order.none() to use the
repository’s default sort (typically { _id: -1 }).Maximum number of documents to return per page. When omitted the repository
returns all matching documents.
1-based page number, not a raw skip value. The repository converts this to
a MongoDB
skip of (offset - 1) * limit. When omitted the query starts
from the first document.Properties
| Property | Type | Description |
|---|---|---|
filters | Filters | The Filters instance passed to the constructor. |
order | Order | The Order instance passed to the constructor. |
limit | number | undefined | Maximum documents per page. |
currentPage | number | undefined | The 1-based page number as supplied to the constructor. This is the raw value you pass in. |
offset | number | undefined | The computed MongoDB skip value: (currentPage - 1) * limit. undefined when limit or the page number is not provided. |
Methods
hasFilters(): boolean
Returns true when the Filters collection contains at least one Filter condition, false otherwise. Useful for conditionally logging or short-circuiting query logic.
Usage Example
The constructor’s
offset parameter is a 1-based page number. Internally,
Criteria stores the page number in currentPage and pre-computes the
MongoDB skip into offset as (currentPage - 1) * limit. If you supply
page 3 with limit: 10, criteria.offset will be 20 — the raw skip
value that MongoDB receives. Always pass 1-based page numbers to the
constructor.