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.

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

On this page