In Mongodb, how do I get the count of the total results returned, without the limit?
L开发者_运维百科et's say i put a limit and skip on the MongoDB query...I want to know the total results if there was not a limit on there.
Of course, I could do this the shitty way...which is to query twice.
In MongoDB the default behavior of count()
is to ignore skip
and limit
and count the number of results in the entire original query. So running count
will give you exactly what you want.
Passing a Boolean true
to count
or calling size
instead would give you a count WITH skip or limit.
There is no way to get the count without executing the query twice.
精彩评论