Assume, that I have bunch of entries in a document:
db.document
and some of them doesn't have some key, let's say name. So we have two types of entries - with and without name.
{ "_id" : ObjectId("4dea81a8bd2bb0323800002d"), "fetched_at" : ISODate("2013-08-02T17:41:30Z"), "keyword" : "110770", "name" : "SOME NAME" }
{ "_id" : ObjectId("4dea81a8bd2bb0323800002a"), "fetched_at" : ISODate("2013-08-02T17:44:17Z"), "keyword" : "125176" }
I want to remove all entries without name
property, because it makes my database incosistent. How can I do that? I tried with null
and undefined
but it doesn't works.
it's possible using $exists:
db.document.remove( { name : { $exists : false } } );