In MongoDB, a Read operation consists of querying the database. This page provides examples.
You can query documents in MongoDB with the following methods:
Your programming language's driver.
The MongoDB Atlas UI. To learn more, see Query for Null or Missing Fields with MongoDB Atlas.
Additional Query Tutorials
For more query examples, see:
Behavior
Cursor
Concurrent Updates While Using a Cursor
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.
Read Isolation
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.
Query Result Format
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.
Query Spill
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.