MongoDB CRUD操作:删除文档
可以使用下面的方式删除MongoDB集合的文档:
- 使用编程语言提供的驱动程序,在应用中调用API进行删除。
- 使用MongoDB Atlas UI删除文档。
- 使用MongoDB Compass、mongosh。
- 使用其他第三方工具。
下面使用mongosh
的删除方法:
db.collection.deleteOne()
db.collection.deleteMany()
对删除操作进行说明。
使用下面的脚本创建inventory
集合,下面的例子会使用inventory
集合:
db.inventory.insertMany( [
{
item: "journal", qty: 25, size: {
h: 14, w: 21, uom: "cm" }, status: "A" },
{
item: "notebook", qty: 50, size: {
h