MongoDB(WiredTiger)返回的计数不正确

编程入门 行业动态 更新时间:2024-10-24 05:16:32
本文介绍了MongoDB(WiredTiger)返回的计数不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这听起来很奇怪,我希望我做错了什么,但是我的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)返回的计数不正确

本文发布于:2023-10-30 19:08:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1543735.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不正确   MongoDB   WiredTiger

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!