ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
删除有`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() ```