生活随笔
收集整理的這篇文章主要介紹了
【MongoDB学习笔记7】深入MongoDB的删除(remove/drop)操作
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
先看集合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?}
刪除指定的文檔: ?
>?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?}
?
刪除所有{“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?}????
>
刪除整個(gè)post集合: ? ?
>?db.post.drop()????
true????
>?show?collections????
system.indexes????
>
轉(zhuǎn)載于:https://blog.51cto.com/281816327/1598301
總結(jié)
以上是生活随笔為你收集整理的【MongoDB学习笔记7】深入MongoDB的删除(remove/drop)操作的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。