【问题标题】:Delete Embedded Document from ListfField in Mongo Engine从 Mongoengine 的列表字段中删除嵌入文档
【发布时间】:2015-11-11 20:47:08
【问题描述】:

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

-Team
    -Players
        -name
        -number

如何删除或更新玩家?

【问题讨论】:

    标签: python mongoengine nosql


    【解决方案1】:

    它应该看起来像这样(注意这些是原始的 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" }})
    

    【讨论】:

      猜你喜欢
      • 2015-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 2016-08-02
      相关资源
      最近更新 更多