Mongster

Guides

Querying

Play with your data

Mongster queries stay close to MongoDB. The main difference is that projections, populate, sorting, and a few other helpers stay typed.

Read queries

import {  } from "./models";

const  = new ();

const  = .({ , : false })
  .(["title", "tags", "createdAt"])
  .({ : -1 })
  .(10)
  .(20);

const  = await ;

find(), findOne(), and findById() return thenable query builders. You can await them directly, but you can also keep building the query before it runs.

Updates and counts

import {  } from "./models";

await .({ :  }, { : { : true }, : { : "done" } });

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

Common helpers

  • include() and exclude() for typed projections.
  • project() when you want to pass a projection record yourself.
  • sort(), skip(), and limit() for cursor shaping.
  • count(), estimatedCount(), and distinct() for collection summaries.
  • explain() returns MongoDB's query plan for the same filter and options.
  • getCursor() hands you the raw FindCursor for streaming or advanced workflows.

Updates, counts, and operators

For the rules Mongster applies to update operators ($set, $inc, $push, $addToSet, $rename, ...), see the Updates guide. That page lists every supported operator with an example and the validation it triggers.

Populate has its own guide because refs come with a few important limitations.

On this page