limit() (Limit Result Count)

Last updated: 2026-10-09

limit() (Limit Result Count)

limit() caps how many documents find() returns: `db.users.find({ age: { $gt: 20 } }).limit(5)`. It chains onto the cursor and is the standard tool for pagination and top-N queries. limit(0) means no limit; it composes freely with other cursor methods, e.g. skip() for paging.

CategoryCursor
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.<collection>.find(<filter>).limit(<count>)

⚙️ Parameters

countMaximum documents to return; 0 means unlimited.

Returns:The cursor with the limit applied (chainable).

▶ Example

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

// limit: take only the first 3 adults
const top3 = db.users.find({ age: { $gte: 18 } }).limit(3).toArray()
top3

Output:

[
  { _id: ObjectId('64c8a1b20000000000000001'), name: 'Alice', age: 21 },
  { _id: ObjectId('64c8a1b20000000000000002'), name: 'Bob', age: 25 }
]

📌 Notes

More hands-on cases coming soon.

📚 Related Tutorials

❓ FAQ

QHow do limit and skip combine for pagination?
ATypical pattern: .skip(pageSize*page).limit(pageSize), e.g. .skip(10).limit(10) for page two of ten.
QWhat does limit(0) mean?
Alimit(0) applies no limit, equivalent to omitting it.
QCan I chain more cursor methods after limit?
AYes — limit() returns a cursor, so sort(), skip(), toArray(), etc. can follow.
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%

🙏 帮我们做得更好

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

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