find() (Query Documents)

Last updated: 2026-10-09

find() (Query Documents)

find() queries documents matching a condition and returns a Cursor. It is the most basic read method: the first argument is the query predicate, the second is the projection controlling returned fields. The cursor is lazy — data is fetched only when iterated (toArray/forEach/next).

CategoryRead
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.<collection>.find(<query>, <projection>)

⚙️ Parameters

queryPredicate object supporting query operators; omitted matches all.
projectionOptional. Controls returned fields: 1 include / 0 exclude.

Returns:Cursor

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// find: users older than 20, name only
const cursor = db.users.find(
  { age: { $gt: 20 } },
  { name: 1, age: 1, _id: 0 }
)
cursor.forEach(u => print(u.name))

Output:

Alice
Bob

📌 Notes

📚 Related Tutorials

❓ FAQ

QDoes find() return an array?
ANo, it returns a Cursor. Convert with .toArray() (or iterate) when you need an array.
QWhat does find() return?
Afind() returns a cursor, not an array. Convert it with toArray(), or iterate with forEach/next; the cursor is lazy and only fetches documents from the server as you read.
QWhat does the second argument of find() do?
AIt is the projection: 1 includes fields, 0 excludes them (mixing is allowed only for _id). Use it to reduce network payload and result size.
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%

🙏 帮我们做得更好

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

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