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.
@abejarano/ts-mongodb-criteria is published to the public npm registry. It
ships dual CJS and ESM builds and a bundled TypeScript declaration file, so it
works with every modern Node.js module system and bundler without extra
configuration. This page covers the full install process, environment variable
reference, module format details, and TypeScript project settings.
Install the Package
Peer Dependency: mongodb
The MongoDB driver is declared as a peer dependency and must be installed separately in your project. Anymongodb release at or above version 6 is
supported:
mongodb is already present in your package.json at version 6 or higher,
no additional step is needed. If it is missing, the library will throw a
runtime error when it tries to open a connection.
Environment Variables
MongoClientFactory reads your connection details from process environment
variables at runtime. The simplest approach is to supply a full connection
string via MONGO_URI:
.env
MONGO_URI value yourself using the component variables before process start:
.env
The library reads only
MONGO_URI. The component variables (MONGO_USER,
MONGO_PASS, MONGO_SERVER, MONGO_DB) are not read by the library
directly. They are shown here as a conventional naming pattern for teams that
assemble the connection string in a startup script or infrastructure layer.dotenv:
CommonJS vs. ESM
The package ships both module formats under thedist/ directory and declares
them via package.json exports so Node.js and bundlers automatically select
the right one:
package.json (library exports — for reference)
| Import style | File served |
|---|---|
import … from "@abejarano/ts-mongodb-criteria" | dist/esm/index.js |
const … = require("@abejarano/ts-mongodb-criteria") | dist/cjs/index.js |
| TypeScript type resolution | dist/types/index.d.ts |
TypeScript Configuration
For TypeScript to resolve the"exports" field in package.json correctly,
set moduleResolution to bundler, node16, or nodenext in your
tsconfig.json:
tsconfig.json
"moduleResolution": "bundler" (recommended for Vite / esbuild / bun
projects):
tsconfig.json
"moduleResolution": "node" does not honour the exports field
and may fail to locate the type declaration file. Upgrade to one of the three
supported strategies above if you see module-resolution errors after install.
Package Exports Reference
The three entrypoints published with the package:| Export condition | Resolved path | Usage |
|---|---|---|
types | dist/types/index.d.ts | TypeScript declarations |
import (ESM) | dist/esm/index.js | import statements, ESM bundlers |
require (CJS) | dist/cjs/index.js | require() calls, CommonJS bundlers |
Criteria, Filters, Order, Operator, MongoRepository,
AggregateRoot, MongoTransaction, IRepository, Paginate, OrCondition,
and OrderTypes) are available from the single package root: