如果给出查询,MongoDB 的 count() 会错误地返回 0
我们的数据库当前正在运行,一切似乎都很好。我想做一些统计,所以我做了一些标准调用。基本上我想要一些特定数据的数量。
首先进行一些基本调用,向您展示数据库中确实有数据。
> db.files.count()
814639
> db.files.find({"migrated":true})
{ "migrated" : true, "filename" : "bleh",... }
...
很明显有数据,调用会返回它。现在我想知道有多少结果,但我得到了:
> db.files.count({"migrated":true})
0
我也这样做了:
> db.files.find({"migrated":true}).count()
0
有人知道为什么会发生这种情况吗?
版本是:
> db.version()
1.8.1
任何帮助将不胜感激
Our database is currently running and everything seems to fine. I wanted to do some statistics so I did some standard calls. Basically I wanted the number of some specific data.
First some basic calls to show you that there actually is data in the database.
> db.files.count()
814639
> db.files.find({"migrated":true})
{ "migrated" : true, "filename" : "bleh",... }
...
So clearly there's data, and the call returns it. Now I want to find out how many results there is, but I get this:
> db.files.count({"migrated":true})
0
And I did this too:
> db.files.find({"migrated":true}).count()
0
Is there anyone who has any idea why this could be happening?
The versions is:
> db.version()
1.8.1
Any help would be much appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题很可能与以下错误有关:
中我的案例(mongodb 2.0.1)与数据库损坏有关。请参阅 find().count() 错误?
It's probable that this question is related to the following bugs:
In my case (mongodb 2.0.1) was related to database corruption. See find().count() bug?
已经有一段时间了,但我现在要关闭它。但这是一个损坏的数据库。必须手动将所有项目从一个数据库移动到新数据库,因为备份在发现损坏的数据时停止,并且随后没有备份有效数据。
Been a while, but I'm closing this now. But it was a corrupt database. Had to manually move all the items from one database to a new one since a backup stopped when it found the corrupt data, and valid data afterwards wasn't being backed up.