【发布时间】:2021-12-01 11:52:24
【问题描述】:
我正在尝试使用 Mongoose/Node 从 MongoDB 中的数组中删除一个对象,但到目前为止我无法将其删除。我已经阅读了文档和 SO 帖子,但没有运气。我希望有人能给我关于解决方案的具体建议,而不仅仅是指向另一个模糊相关的帖子的链接
Mongo 文档示例
{
managers: [{
userID: value,
// other fields and values
},
// Another object for another manager
]
}
我正在尝试使用的代码
await Model.updateMany(
{'managers.userID': userID}, // This should be the query part
{$pullAll: {'managers': {'userID': userID}}} // This should be the update part
)
【问题讨论】:
标签: node.js database mongodb mongoose