Mongster

Model

Typed collection API and transaction-scoped models

Models expose the collection-level API you use most often. Transaction-scoped models created through ctx.use(Model) keep the same surface, but inject a session automatically.

import { ,  } from "mongster";

const  = .({
  : .(),
  : .().(false),
}).();

const  = ("tasks", );

await .({ : "Write docs" });
await .({ : false }).(5);
await .({ : "Write docs" }, { : { : true } });
await .({ : true });

const  = await .().({ : true }).("done").();

Read surface

  • find
  • findOne
  • findById
  • count
  • estimatedCount
  • distinct

Write surface

  • insertOne, insertMany
  • createOne, createMany
  • updateOne, updateMany, findOneAndUpdate
  • replaceOne, findOneAndReplace, upsertOne
  • deleteOne, deleteMany, findOneAndDelete
  • bulkWrite

Extra helpers

  • populate
  • aggregate
  • aggregateRaw
  • syncIndexes
  • getCollection
  • getCollectionName
  • pre and post

Transaction models

ctx.use(Model) returns a transaction model with the same CRUD and query helpers. The difference is that the session is already wired into every operation.

On this page