更新时间:2023-11-30 22:33:10
您需要使用位置 $
更新操作符,用于从数组中删除元素.您需要这样做是因为节"是子文档的数组.
You need to use the positional $
update operator to remove the element from your array. You need this is because "sections" is an array of sub-documents.
db.test.findOneAndUpdate(
{ "sections._id" : ObjectId("56fea43a571332cc97e06d9e") },
{ "$pull": { "sections.$.registered": "e3d65a4e-2552-4995-ac5a-3c5180258d87" } }
)