这听起来很奇怪,我希望我做错了什么,但是我的MongoDB集合正在将我的集合中的Count返回一个.
This sounds odd, and I hope I am doing something wrong, but my MongoDB collection is returning the Count off by one in my collection.
我有一个集合(我确信)有359671个文档.但是count()命令返回359670文档.
I have a collection with (I am sure) 359671 documents. However the count() command returns 359670 documents.
我正在使用mongo shell执行count()命令:
I am executing the count() command using the mongo shell:
rs0:PRIMARY> db.COLLECTION.count() 359670这是不正确的.
它并没有找到我收藏中的每个文档.
It is not finding each and every document in my collection.
如果我提供以下查询来计数,则会得到正确的结果:
If I provide the following query to count, I get the correct result:
rs0:PRIMARY> db.COLLECTION.count({_id: {$exists: true}}) 359671我相信这是WiredTiger中的错误.据我所知,每个文档都具有相同的定义,一个_id字段(范围为0到359670的整数)和BinData字段.使用较旧的存储引擎(或Mongo 2,可能是造成此问题的原因)时,我没有这个问题.
I believe this is a bug in WiredTiger. As far as I am aware each document has the same definition, an _id field of an integer ranging from 0 to 359670, and a BinData field. I did not have this problem with the older storage engine (or Mongo 2, either could have caused the issue).
这是我做错了吗?我不想使用{_id: {$exists: true}}查询,因为它需要100倍的时间才能完成.
Is this something I have done wrong? I do not want to use the {_id: {$exists: true}} query as that takes 100x longer to complete.
推荐答案根据此问题,如果mongodb遇到硬崩溃并且无法正常关闭,则会发生此行为.如果不发出任何查询,则mongodb可能会退回到收集的统计信息中.
According to this issue, this behaviour can occur if mongodb experiences a hard crash and is not shut down gracefully. If not issuing any query, mongodb probably just falls back to the collected statistics.
根据该文章,调用db.COLLECTION.validate(true)应该重置计数器.
According to the article, calling db.COLLECTION.validate(true) should reset the counters.
更多推荐
MongoDB(WiredTiger)返回的计数不正确
发布评论