For AI agents: a documentation index is available at https://www.mongodb.com/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Read Documents

In MongoDB, a Read operation consists of querying the database. This page provides examples.

You can query documents in MongoDB with the following methods:

For more query examples, see:

As a cursor returns documents, other operations may run in the background and affect the results, depending on the read concern level. For details, see Read Isolation, Consistency, and Recency.

For reads to replica sets and replica set shards, read concern lets clients choose an isolation level for their reads. For more information, see Read Concern.

When you run a find operation with a MongoDB driver or mongosh, MongoDB returns a cursor that manages query results. Query results are not returned as an array of documents.

To learn how to iterate through documents in a cursor, see your driver's documentation. If you are using mongosh, see Iterate a Cursor in mongosh.

A query that exceeds either 100 megabytes or the available memory spills to disk. It writes intermediate data to storage to save memory, which can cause lowered performance. Use the allowDiskUseByDefault parameter or cursor.allowDiskUse() method to configure this behavior.

For Atlas deployments using Atlas Infinite, compute and storage are separated, so queries spill to the compute node executing the query. For more information, see query spilling on Atlas Infinite clusters.

Earn a Skill Badge

Master "Query Optimization" for free!

Learn more

Rate this page