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:
Query Documents (MongoDB Manual) — worked
find()examples from equality matches to operator, AND, and OR conditions, with a SQL-to-MongoDB comparison.