使用 remove()
方法從集合移除文檔尽爆。這個方法根據(jù)條件文檔決定要刪除的文檔。
條件文檔的結(jié)構(gòu)和語法與查詢條件一致,見 Find or Query Data with the mongo Shell。
刪除所有適配的文檔
db.restaurants.remove( { "borough": "Manhattan" } )
remove()
默認(rèn)刪除所有適配的文檔各谚,可以使用 justOne 參數(shù)限制只刪除一條適配的文檔。
db.restaurants.remove( { "borough": "Queens" }, { justOne: true } )
刪除所有文檔
db.restaurants.remove( { } )
刪除集合
remove()
只能刪除集合內(nèi)的文檔到千。對于集合自身昌渤,以及集合的索引,可以使用 drop()
刪除整個集合憔四,包含索引在內(nèi)膀息。
db.restaurants.drop()
操作成功將會返回 true般眉,否則返回 false。