我还没有找到明确的答案,但问题是我需要删除和/或更新列表字段中的嵌入文档。所以如果我有一个模式:
-Team
-Players
-name
-number
如何删除或更新玩家?
最佳答案
它应该看起来像这样(注意这些是原始的 mongodb 查询):
# 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" }})
关于python - 从 Mongoengine 中的列表字段中删除嵌入文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33659540/