开发者

MongoDB's count() incorrectly returns 0 if a query is given

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}).cou开发者_如何学运维nt()
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


It's probable that this question is related to the following bugs:

  • Interrupted count query returns 0 as count result
  • count command returns zero in some error cases rather than reporting an error with ok:false

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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜