开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜