欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MongoDB快速入門(mén)筆記(六)之MongoDB刪除文檔操作

 更新時(shí)間:2016年06月01日 09:25:29   作者:tiger_zhang  
這篇文章主要介紹了MongoDB快速入門(mén)筆記(六)之MongoDB刪除文檔操作 的相關(guān)資料,需要的朋友可以參考下

MongoDB是一個(gè)跨平臺(tái),面向文檔的數(shù)據(jù)庫(kù),提供高性能,高可用性和易于擴(kuò)展。MongoDB是工作在集合和文檔上一種概念。

文檔是一組鍵值對(duì)。文檔具有動(dòng)態(tài)模式。動(dòng)態(tài)模式是指,在同一個(gè)集合的文件不必具有相同一組集合的文檔字段或結(jié)構(gòu),并且相同的字段可以保持不同類(lèi)型的數(shù)據(jù)。

db.集合名稱(chēng).remove({query}, justOne)

query:過(guò)濾條件,可選

justOne:是否只刪除查詢(xún)到的第一條數(shù)據(jù),值為true或者1時(shí),只刪除一條數(shù)據(jù),默認(rèn)為false,可選。

準(zhǔn)備數(shù)據(jù):把_id為1和2的age都變成28

> db.student.update({_id:1},{$set:{age:28}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.student.update({_id:2},{$set:{age:28}})
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.student.find()
{ "_id" : 1, "name" : "zhangsan", "age" : 28 }
{ "_id" : 2, "name" : "lisi", "age" : 28 }
{ "_id" : 3, "name" : "wangwu", "age" : 30 }
{ "_id" : 4, "name" : "zhaoliu", "age" : 28 }
{ "_id" : 5, "name" : "qianliu", "age" : 33 }
{ "_id" : 6, "name" : "sunba", "age" : 32 }
{ "_id" : 7, "name" : "songjiu", "skill" : [ "mongodb", "java" ] }

1、使用兩個(gè)參數(shù):

刪除age=28的第一條數(shù)據(jù)

> db.student.remove({age:28}, true)
WriteResult({ "nRemoved" : 1 })
> db.student.find()
{ "_id" : 2, "name" : "lisi", "age" : 28 }
{ "_id" : 3, "name" : "wangwu", "age" : 30 }
{ "_id" : 4, "name" : "zhaoliu", "age" : 28 }
{ "_id" : 5, "name" : "qianliu", "age" : 33 }
{ "_id" : 6, "name" : "sunba", "age" : 32 }
{ "_id" : 7, "name" : "songjiu", "skill" : [ "mongodb", "java" ] } 

2、使用一個(gè)參數(shù):

刪除age=28的所有數(shù)據(jù)

> db.student.remove({age:28})
WriteResult({ "nRemoved" : 2 })
> db.student.find()
{ "_id" : 3, "name" : "wangwu", "age" : 30 }
{ "_id" : 5, "name" : "qianliu", "age" : 33 }
{ "_id" : 6, "name" : "sunba", "age" : 32 }
{ "_id" : 7, "name" : "songjiu", "skill" : [ "mongodb", "java" ] } 

3、刪除集合的全部數(shù)據(jù),括號(hào)中的“{}”必須有,表示空的過(guò)濾條件:

> db.student.remove({})
WriteResult({ "nRemoved" : 4 }) 

另外使用remove()方法刪除的時(shí)候,只是刪除數(shù)據(jù),表還會(huì)存在。使用drop()方法會(huì)把表也刪除,并且drop()的效率要比remove()效率高很多。

相關(guān)文章

  • mongodb?linux下集群搭建過(guò)程

    mongodb?linux下集群搭建過(guò)程

    這篇文章主要介紹了mongodb?linux下集群搭建過(guò)程,本例中,為每個(gè)集群(shard?config)三個(gè)mongo實(shí)例,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • MongoDB排序時(shí)內(nèi)存大小限制與創(chuàng)建索引的注意事項(xiàng)詳解

    MongoDB排序時(shí)內(nèi)存大小限制與創(chuàng)建索引的注意事項(xiàng)詳解

    在數(shù)據(jù)量超大的情形下,任何數(shù)據(jù)庫(kù)系統(tǒng)在創(chuàng)建索引時(shí)都是一個(gè)耗時(shí)的大工程,下面這篇文章主要給大家介紹了關(guān)于MongoDB排序時(shí)內(nèi)存大小限制與創(chuàng)建索引的注意事項(xiàng)的相關(guān)資料,需要的朋友可以參考下
    2022-05-05
  • java操作mongoDB查詢(xún)的實(shí)例詳解

    java操作mongoDB查詢(xún)的實(shí)例詳解

    這篇文章主要介紹了java操作mongo查詢(xún)的實(shí)例詳解的相關(guān)資料,希望通過(guò)本文能幫助到大家,需要的朋友可以參考下
    2017-09-09
  • MongoDB服務(wù)端JavaScript腳本使用方法

    MongoDB服務(wù)端JavaScript腳本使用方法

    這篇文章主要介紹了MongoDB服務(wù)端JavaScript腳本使用方法,需要的朋友可以參考下
    2015-10-10
  • 最新評(píng)論