ts-mongo-criteria is a TypeScript library that brings the Criteria Pattern to MongoDB. Instead of writing raw query objects, you compose type-safeDocumentation 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 instances that translate automatically into MongoDB filters, sort specs, and paginated results — with zero boilerplate.
Quickstart
Get a working query running in under 5 minutes.
Installation
Install via npm, yarn, pnpm, or bun and configure your environment.
Criteria Pattern
Understand the design pattern powering the library.
Operators Reference
All 12 filter operators with MongoDB equivalents and examples.
Repository Setup
Build a full repository with indexes, pagination, and upsert.
API Reference
Complete type signatures for every exported class and interface.
What you get
12 Operators
EQUAL, GT, BETWEEN, CONTAINS, OR, IN, and more — all mapped to native MongoDB operators.
Pagination Built In
MongoRepository.list() returns Paginate<T> with nextPag, count, and results.Atomic Transactions
Wrap multi-repository writes in
MongoTransaction.run() for all-or-nothing semantics.Dual CJS + ESM
Ships with CommonJS, ESM, and TypeScript declaration files — works in any modern setup.
Lazy Index Registration
Override
ensureIndexes() once; the base class calls it automatically the first time a collection is accessed.DDD Ready
AggregateRoot, ValueObject, and IRepository<T> primitives integrate cleanly into domain layers.Quick look
Criteria object above converts to the following MongoDB query automatically: