🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
删除有`remove`和`deleteOne`、`deleteMany`,`remove`已过时但还能用。 <br/> **1. `deleteMany`** 删除符合条件的所有文档。 ```sql # 删除price<6000的文档 > db.goods.deleteMany({"price":{$lt:6000}}) { "acknowledged" : true, "deletedCount" : 8 } > db.goods.find() { "_id" : 1, "contry" : "中国" } { "_id" : 10, "name" : "apple10", "addr" : "苹果旗舰店10", "contry" : "中国10", "price" : 6000 } { "_id" : 11, "name" : "apple11", "addr" : "苹果旗舰店11", "contry" : "中国11", "price" : 6100 } { "_id" : 12, "name" : "apple12", "addr" : "苹果旗舰店12", "contry" : "中国12", "price" : 6200 } ``` <br/> **2. `deleteOne`** 删除符合条件的第一个文档。 ```sql # 删除price<6200的的第一个文档 > db.goods.deleteOne({"price":{$lt:6200}}) { "acknowledged" : true, "deletedCount" : 1 } > db.goods.find() { "_id" : 1, "contry" : "中国" } { "_id" : 11, "name" : "apple11", "addr" : "苹果旗舰店11", "contry" : "中国11", "price" : 6100 } { "_id" : 12, "name" : "apple12", "addr" : "苹果旗舰店12", "contry" : "中国12", "price" : 6200 } { "_id" : 13, "name" : "apple13", "addr" : "苹果旗舰店13", "contry" : "中国13", "price" : 6300 } ``` <br/> **3. 清空一个Collection** ```sql > db.goods.deleteMany({}) { "acknowledged" : true, "deletedCount" : 21 } > db.goods.find() ```