Get the App
SLTechnology News&Howtos  ›  Database  › 

[MongoDB Learning Notes 7] go deep into the remove/drop operation of MongoDB

Shulou Source: shulou.com Published: 2022-06-01 05:45:51 10月04日 Update

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 >

Tags: Documents information notes learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Huawei Apple macOS MySQL