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.

CategoryAdmin Commands
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.orders.find({ status: "shipped" }).limit(10)
db.runCommand({
  find: "orders",
  filter: { status: "shipped" },
  limit: 10
})

⚙️ Parameters

filterThe query predicate document
projectionField selection (1 include / 0 exclude)
sort/limit/skipSort 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

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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏