我还没有找到明确的答案,但问题是我需要删除和/或更新列表字段中的嵌入式文档。所以,如果我有一个架构:
-Team
-Players
-name
-number
我该如何删除或更新玩家?
答案 0 :(得分:1)
It should look like this (note these are raw mongodb queries):
# To update the number:
db.team.update({ "name": "FC Barcelona", "players.name" : "Lionel Messi" }, { $set: { "players.$.number" : 11 }})
# To remove the player from the list:
db.team.update({ "name": "FC Barcelona", "players.name" : "Cesc Fabregas" }, { $pull: { "players.name" : "Cesc Fabregas" }})