In Mongodb, how do I get a count of the final results, without limitation?

Say I set a limit and skipped a MongoDB query ... I want to know the final results if there was no limit.

Of course, I could do it in a shitty way ... which I have to query twice.

+8
database indexing mongodb
source share
2 answers

In MongoDB, the default behavior of count() means 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 boolean true to count or calling size instead will give you a counter with a skip or limit.

+14
source share

There is no way to get the counter without executing the request twice.

-2
source share

All Articles