find (Query Documents)
Last updated: 2026-10-09
find (Query Documents)
find is MongoDB's query command. mongosh normally uses the helper db.collection.find(filter, projection); the raw form is db.runCommand({ find: 'orders', filter: {...} }). It supports filter, projection, sort, limit, skip, and batchSize. The result is a cursor; a non-zero id needs getMore for further batches.
| Category | Admin Commands |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
db.orders.find({ status: "shipped" }).limit(10)
db.runCommand({
find: "orders",
filter: { status: "shipped" },
limit: 10
})
⚙️ Parameters
| filter | The query predicate document |
|---|---|
| projection | Field selection (1 include / 0 exclude) |
| sort/limit/skip | Sort order, result cap, and skip |
Returns:Returns a cursor; firstBatch holds matches, getMore for further batches when id is non-zero
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// find: raw command form
use shop
db.runCommand({
find: 'orders',
filter: { status: 'shipped' },
sort: { createdAt: -1 },
limit: 5
})
Output:
{ cursor: { firstBatch: [ { _id: ObjectId('...'), status: 'shipped' } ], id: 0, ns: 'shop.orders' }, ok: 1 }
📌 Notes
- The find() helper suffices daily; the raw form fine-tunes batchSize
- Cursor results with id != 0 require getMore
- Check index usage with explain()
🏷️ Related Tags
💡 Related Cases
More hands-on cases coming soon.
📚 Related Tutorials
❓ FAQ
QHow does findOne relate to find?
AfindOne wraps find with limit: 1 and returns the first document.
QHow do I fetch all cursor results?
ACall toArray() or iterate; the driver issues getMore automatically when id is non-zero.
QHow do I inspect query performance?
ARun explain() and check index usage plus executionStats.