[英]Why mongo db (version 3.0.6) returns wrong number of records when we use count with limit option?
As per mongo db doc says we can use count with limit. 正如mongo db doc所说,我们可以将count与limit一起使用。
Limit option is used to specify the maximum number of documents the cursor will return. 限制选项用于指定光标将返回的最大文档数。 But if we use limit with count it returns total count and not correct count. 但是,如果我们将限制与计数一起使用,它将返回总计数,而不是正确的计数。
Why? 为什么?
Suppose we have 50 records in collection then only count option will return 50, and if we apply limit(10) option then it should return 10 and not 50. But count with limit returns 50. 假设我们在集合中有50条记录,那么只有count选项将返回50,如果我们应用limit(10)选项,则它将返回10而不是50。但是带有limit的计数将返回50。
db.collection.find(<query>).count();
You will get count of all records found after executing the query. 执行查询后,您将获得所有找到的记录的计数。 ie count=50; 即计数= 50;
db.collection.find(<query>).limit(10).count(true);
You will get the count of limited documents. 您将获得有限文件的数量。 ie count=10. 即计数= 10。
You should set applySkipLimit
to true. 您应该将applySkipLimit
设置为true。
http://docs.mongodb.org/manual/reference/method/cursor.count/ http://docs.mongodb.org/manual/reference/method/cursor.count/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.