Saturday, January 21, 2017

remove/delete

remove/delete
=============

db.collectionname.remove({expr})

db.test.find({_id:100})
db.test.find({_id:100}).count()

db.test.remove({_id:100})

remove all=>db.test.remove({})

db.test.remove({x:/ello/})

Example:
Suppose we have documents in the users collection of the form:
{
 _id : ObjectId("50897dbb9b96971d287202a9"),
 name : "Jane",
 likes : [ "tennis", "golf" ],
 registered : false,
 addr : {
   city : "Lyon",
   country : "France"
 }
}
How would we, in the mongo shell, delete all documents in the collection where city is "Lyon" and registered is false?

No comments:

Post a Comment