freeall
freeall

Reputation: 3208

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}).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

Upvotes: 5

Views: 6428

Answers (2)

freeall
freeall

Reputation: 3208

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.

Upvotes: 1

sw.
sw.

Reputation: 3231

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?

Upvotes: 1

Related Questions