Reputation: 153
> db.things.find()
{ "_id" : ObjectId("561d640e7ce0a090519b3a0d"), "f" : 7, "d" : 4, "e" : 5 }
{ "_id" : ObjectId("561d64127ce0a090519b3a0e"), "d" : 4, "e" : 5 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a0f"), "x" : 0 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a10"), "x" : 1 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a11"), "x" : 2 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a12"), "x" : 3 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a13"), "x" : 4 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a14"), "x" : 5 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a15"), "x" : 6 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a16"), "x" : 7 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a17"), "x" : 8 }
{ "_id" : ObjectId("561d643c7ce0a090519b3a18"), "x" : 9 }
The documentation lists a command for removing an individual item with this syntax:
> db.things.remove({ "x" : 0 })
This would remove the third listed object.
What I'm wondering is if there a single command for removing all objects with a key of "x" in the above code?
Upvotes: 1
Views: 22
Reputation: 44288
you can use $exists
db.things.remove({ x: { $exists: true } });
http://docs.mongodb.org/manual/reference/operator/query/exists/
Upvotes: 2