LOGBOOK

HELP

Quiz Entry - updated: 2026.07.05

How do you query documents from a MongoDB collection?

Call find() with a query object to get a cursor, then toArray() to materialize the matching documents.

const results = await collection.find(
  { day: { $gt: new Date('2000-01-01') } },
  { sort: { name: 1 } }
).toArray();

Parameters:

  • <query> - object describing which documents to match
  • <options> - object for sorting, projection, etc.

Warning: find().toArray() loads ALL matching documents into memory.

Go deeper:

From Quiz: WEBT / Database Connections | Updated: Jul 05, 2026