Inconsistent results being returned by mongodb find query
I ran the following query on a collection in my mongodb database.
db.coll.find({field_name:{$exists:true}}).count()
and it returned 24371开发者_如何转开发85. The total records reported by db.coll.find({}).count()
is 2437228 .
Now when i run the query db.coll.find({field_name:{$exists:false}}).count()
, instead of returning 43 it returned 0.
I have the following two questions :
Does the above scenario mean that the data in my collection has become corrupt ?.
I had posted a question earlier about this at ( Updating records in MongoDB through pymongo leads to deletion of most of them). The person who replied said that updating data in mongo db could blank out the data but not delete it. What does that mean ?.
Thank You
I believe you're running into the issue reported at SERVER-1587. What version of MongoDB are you using? If it is less than 1.9.0, you can use the following as a work-around:
db.coll.find({field_name: {$not: {$exists: true}}}).count()
As for the other question, "blanking out" in this case means that an update can change the value of or unset any or all fields in a document, but can't remove the document itself. The only way to remove a document is with remove()
精彩评论