mongodb删除嵌套文档
时间: 2023-08-30 11:04:45 浏览: 108
在MongoDB中删除嵌套文档可以使用$pull操作符。具体操作如下:db.集合名称.update( {"results._id":ObjectId("5cd01dfc5d157b5d9bc27597")}, {$pull:{results.$.relation_kpi_draft:{_id:ObjectId("5cd01dfc5d157b5d9bc2750d")}}})。这个操作会在results._id为"5cd01dfc5d157b5d9bc27597"的文档中的relation_kpi_draft数组中删除_id为"5cd01dfc5d157b5d9bc2750d"的文档。如果需要删除多个文档,可以使用$in操作符。\[3\]
#### 引用[.reference_title]
- *1* [MongoDB操作内嵌文档](https://blog.csdn.net/qq_45948222/article/details/119708960)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [mongodb 内嵌文档 增删改查](https://blog.csdn.net/m0_67918035/article/details/129383897)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [使用mongodb增删改查深层嵌套文档](https://blog.csdn.net/qq_42427109/article/details/90635466)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文