Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the limit for number of docs returned in a query? #7188

Closed
govindrai opened this issue Oct 28, 2018 · 3 comments
Closed

What is the limit for number of docs returned in a query? #7188

govindrai opened this issue Oct 28, 2018 · 3 comments
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary

Comments

@govindrai
Copy link

When I invoke a Model.find() query, if there are a million docs in the database, will all million be returned? What is the output if there are still more documents to query from the database than are returned? I couldn't find this in the docs (except for information on cursor, which I hope I don't need to use). Thanks!

@govindrai govindrai changed the title What is the limit for number of docs returned in a find query? What is the limit for number of docs returned in a query? Oct 28, 2018
@lineus
Copy link
Collaborator

lineus commented Oct 31, 2018

if there are a million docs in the database, will all million be returned?

Yes. The native driver will attempt to return all of the docs that match your query right up until the point where your node process runs out of memory.

What is the output if there are still more documents to query from the database than are returned?

All matching documents will be returned or you will run out of heap space and your node process will fail.

@vkarpov15 should we add a note to this effect in the docs somewhere?

@lineus lineus added docs This issue is due to a mistake or omission in the mongoosejs.com documentation help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary labels Oct 31, 2018
@vkarpov15
Copy link
Collaborator

You can use limit() to limit the number of docs your query returns, or cursor() to process documents one at a time. Otherwise, find() will give you an array of all documents that match the filter parameter.

vkarpov15 added a commit that referenced this issue Nov 1, 2018
@vkarpov15
Copy link
Collaborator

@lineus done 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This issue is due to a mistake or omission in the mongoosejs.com documentation help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

3 participants