[MongoDB Learning Notes 7] go deep into the remove/drop operation of MongoDB
First, take a look at the document information in the collection post:
> 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 >