-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Using limit() in count queries is ignored #8811
Comments
Thanks for opening this issue!
|
I think that's how it's supposed to work, count the total of the query, to you know how many pages with skip/limit you can navigate. |
It can still count 100k+ rows for my use case (counting a user's unread messages) when I try to limit it to 100, it's a bit unnecessary. |
The MongoDB |
but if you put a limit of 100, what do you expect to be the count result? |
A value between 0 and 100 :) |
I see, but as I said before, the count is to know how many times you can page it. |
I agree with @matheusfrozzi here. Altering the current behaviour of the |
This is primarily a syntax question. Whether there are use cases for it is a different topic. I believe the expected behavior of There is of course a practical aspect to it. If you want to know whether a collection of In fact, MongoDB hints towards that: cursor.limit says:
cursor.count also provides a specific example: db.orders.find( { ord_dt: { $gt: new Date('01/01/2012') } } ).limit(5).count(true) Since MongoDB explicitly supports the optional |
New Issue Checklist
Issue Description
Using
.limit(X)
in acount()
query is ignored.Steps to reproduce
Run a query with
.limit(X)
on a collection.Actual Outcome
The count result is the number of rows matching the query, which can be greater than the specified limit.
Expected Outcome
The count is the smallest of the number of rows and the X in
.limit(X)
.Environment
Server
6.5.0-beta.1
Ubuntu 22
local
Database
MongoDB
5.3.2
local
Logs
The text was updated successfully, but these errors were encountered: