Ok, so I am attempting to unveil a little update to my website. One update includes querying upon a area that might exist. This does not act as I would like, and so i made the decision to simply allow it to be to ensure that the area always is available during my database. I made use of this line in the MongoDB spend:

> db.entries.update({Published: null},{$set: {Published: true}},false,true);

Now, I am not fully focusing on how this triggered every entry object where Released is null to become erased. I am talking about, it literally was erased. I attempted searching for some IDs, and .findOne will return null on their behalf.

So how exactly does that line work? I figured it might take every entry where Released is null(does not exist), and hang Released to true.

Reading through about operator behavior is preferable to speculating operator behavior. Look for null differs from carrying out a cheque for existence.

MongoDB includes a devoted $is available operator:


To tell the truth, I am unsure why it now works together with changes, or at best, why it erased everything with this command.

My ending command appeared as if this:

db.entries.update({Published: {$exists: false},$atomic: true},{$set:{"Published":true}},false,true);

I figured it might take every entry where Released is null(does not exist), and hang Released to true.

OK, so they are two various things.

Released is null:

{ Published : null, post : 'blah' }

Released doesn't exist:

{ post : 'blahblah' }

You might want to publish this at the MongoDB user group (designers check it very frequently) at http://groups.google.com/group/mongodb-user

Updates don't remove documents. Actually, the update you went does that which you intended, for instance, should you wanted y to continually possess a value:

> db.foo.insert({x:1})
> db.foo.insert({x:2})
> db.foo.insert({y:null})
> db.foo.insert({y:1})
> db.foo.update({y:null},{$set : {y:true}}, false, true)
> db.foo.find()
{ "_id" : ObjectId("4db02aabbe5a5418fb65d24c"), "y" : true }
{ "_id" : ObjectId("4db02aafbe5a5418fb65d24d"), "y" : 1 }
{ "_id" : ObjectId("4db02aa1be5a5418fb65d24a"), "x" : 1, "y" : true }
{ "_id" : ObjectId("4db02aa4be5a5418fb65d24b"), "x" : 2, "y" : true }

There should have been another operation that did the remove. There can be an eye on it within the logs (or there may not... it is dependent how lengthy it required). You can't really tell in the info here what triggered the deletions, however the update is not the reason here.