First look at the collection post Chinese file information:
> Db.post.find (); {"_id": ObjectId ("54A51CFD7F46906F81B7ADCD"), "bar": "Baz"} {"_id": 0} {"_id": 1} {"_id": 2} {"_id": 5, "Test1": 0} {"_id": 4, "Test2": 2} {"_id": 3 , "Test3": 3} {"_id": 6, "TEST5": 5} {"_id": 7, "Test1": 1} {"_id": 8, "Test1": 1}
Delete the specified document:
> Db.post.remove ({"_id": 5}); Writeresult ({"nremoved": 1}) > Db.post.find (); {"_id": ObjectId ("54A51CFD7F46906F81B7ADCD"), "bar": "Baz"} {"_id": 0} {"_id": 1} {"_id": 2} {"_id": 4, "Test2": 2} {"_id": 3, "Test3": 3} {"_id": 6 , "Test5": 5} {"_id": 7, "Test1": 1} {"_id": 8, "Test1": 1}
Delete all documents for {"Test1": 1}:
> Db.post.remove ({"Test1": 1}); Writeresult ({"Nremoved": 2}) > Db.post.find (); {"_id": ObjectId ("54A51CFD7F46906F81B7ADCD"), "bar": "Baz"} {"_id": 0} {"_id": 1} {"_id": 2} {"_id": 4, "Test2": 2} {"_id": 3, "Test3": 3} {"_id": 6 , "Test5": 5} >
Delete the entire post collection:
> Db.post.drop () True > show Collections system.indexes >
This article is from the "Margin with Wish" blog, please be sure to keep this source http://281816327.blog.51cto.com/907015/1598301
MongoDB Learning Note 7 Deep MongoDB Delete (remove/drop) operation