从Mongo Engine中的ListfField中删除嵌入式文档

时间:2015-11-11 20:47:08

标签: python mongoengine nosql

我还没有找到明确的答案,但问题是我需要删除和/或更新列表字段中的嵌入式文档。所以,如果我有一个架构:

-Team
    -Players
        -name
        -number

我该如何删除或更新玩家?

1 个答案:

答案 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" }})