ReadonlynameThe name of the store (e.g. 'mongodb', 'redis', 'dynamodb')
ReadonlylibraryThe client library being used
Returns the underlying native MongoClient.
Returns the underlying native Db handle for the configured database.
Typed collection accessor, e.g. store.collection<User>('users').
Like find, but returns the native FindCursor instead of
materializing the results with toArray(). Use this for large result
sets that shouldn't be pulled fully into memory - iterate with
for await (const doc of cursor) or use cursor.next()/cursor.forEach().
Optionaloptions: CountDocumentsOptionsReturns a fast, metadata-based approximate count of all documents in
collectionName. Unlike countDocuments, this does not accept a
filter and does not scan the collection - it reads the collection's
cached document count, so it's cheap but can be stale/approximate
(e.g. immediately after bulk writes, or on a sharded cluster).
Optionaloptions: EstimatedDocumentCountOptionsOptionaloptions: AggregateOptionsReturns the distinct values for field across documents matching filter.
Optionaloptions: DistinctOptionsTranslate an ORM where object (with Op.* operators and
Op.and/Op.or/Op.not) into a native MongoDB filter document. Exposed
for callers that want to feed the translated filter into other native
operations (e.g. aggregate, watch).
Fetch all documents in collectionName matching an ORM where clause,
with optional ordering, offset, limit, and projection. The where object
accepts the full ORM operator surface (Op.gt, Op.in, Op.between,
Op.like, Op.and/Op.or, ...), translated to a native MongoDB filter -
so standard queries never require hand-written $-filters.
Fetch the first document in collectionName matching an ORM where clause (respecting order), or null.
Count documents in collectionName matching an ORM where clause.
Update every document in collectionName matching an ORM where clause,
applying patch (a raw $-update, or a plain object which is wrapped in
$set).
Delete every document in collectionName matching an ORM where clause.
Optionaloptions: DeleteOptionsInsert-or-update by an ORM where clause: applies patch to a matching
document, inserting one (with the patch merged over the filter's implied
fields) if none matches. Thin wrapper over updateOne with upsert: true.
Grouped aggregation over collectionName using a native
$match/$group pipeline (count/sum/avg/min/max), with an
optional ORM where pre-filter. Returns one entry per group:
{ group, ...aggregates } (group is null when no groupBy is given).
Fetch documents from collectionName matching an ORM where clause, with
one or more associations eager-loaded via native $lookup (the MongoDB
equivalent of a SQL join / ORM include). Each MongoInclude
attaches matched documents under its as key; single: true unwinds to a
single document for to-one associations.
Executes a mix of insert/update/delete/upsert operations against a
single collection in one round trip. Thin passthrough to the native
driver's Collection.bulkWrite().
Optionaloptions: BulkWriteOptionsLists the indexes defined on collectionName. Fills the asymmetry with
createIndex/dropIndex, which have no built-in way to
inspect what indexes already exist. Thin passthrough to the native
driver's Collection.listIndexes().toArray().
Optionaloptions: AbstractCursorOptionsExplicitly creates collectionName, rather than relying on MongoDB's
implicit creation of a collection on first write. This is the only way
to create a timeseries collection (options.timeseries: { timeField, metaField?, granularity? }) or a view (options.viewOn +
options.pipeline), since both must be declared at creation time -
previously this required dropping down to getDb().createCollection(...)
directly.
Optionaloptions: CreateCollectionOptionsLists the collections (and views) defined in the configured database.
Thin passthrough to the native driver's Db.listCollections().toArray().
Optionaloptions: ListCollectionsOptionsRenames oldName to newName. Uses Db.renameCollection() (rather
than Collection.rename()) because it's the driver API that stays
generic over the document type, matching the rest of this class's
typed-collection conventions.
Optionaloptions: RenameOptionsDrops collectionName entirely. Thin passthrough to Collection.drop().
Optionaloptions: DropCollectionOptionsOpens a change stream on collectionName, delivering real-time
notifications of insert/update/replace/delete operations. Thin
passthrough to the native driver's Collection.watch().
Like withTransaction, this requires a replica set / sharded
cluster deployment - a standalone mongod does not support change
streams (see README "Known limitations").
Returns the native ChangeStream, which is itself an async iterable
and event emitter (on('change', ...), on('error', ...), close()).
const stream = store.watch<User>('users', [{ $match: { operationType: 'insert' } }]);
stream.on('change', (change) => {
// change.operationType, change.fullDocument, ...
});
// later: await stream.close();
Optionalpipeline: Document[]Optionaloptions: ChangeStreamOptionsStarts a new client session (for multi-document transactions).
Optionaloptions: ClientSessionOptionsRuns fn inside a MongoDB multi-document transaction. Requires a
replica set / mongos deployment - standalone servers do not support
transactions (see README "Known limitations").
Optionaloptions: TransactionOptions
MongoStorewraps the officialmongodbdriver'sMongoClient/Db/CollectionAPI in a small, typed convenience layer.