MongoDB阵列数据删除

时间:2018-07-06 10:03:51

标签: arrays mongodb mongodb-query

这是我拥有的数据,我要在与用户ID匹配时删除该特定monitorId的数组

            layout = go.Layout(
                title=field+ "_its diff_value chart",
                xaxis = dict(
                    tickformat = '%b %d %Y %H:%M:%S'
                )
            )

这是我的查询

  {
       "_id" : ObjectId("5afd8d562b2de0034953fdae"),
       "isActiveEnabled" : true,
       "isFrEnabled" : null,
       "isDriveEnabled" : true,
       "organization" : "5747f009544abb2ecbccae5f",
       "monitorList" : [
           {
               "timeFailSmsAlert" : false,
               "emailAlert" : true,
               "alcoholSmsAlert" : true,
               "failEmailAlert" : false,
               "displayName" : "t",est
               "username" : "test",
               "monitorId" : "5748fcb6c9e3deeb30d8c74f",
               "organization" : "5747f009544abb2ecbccae5f"
           }
       ],
       "userId" : "5afd8d542b2de0034953fdac"
    }

这是我得到的输出,基本上我想删除

db.getCollection("userconfigs").update({'userId':'5b2f276ea93966a93474006e'},{$pull:{'monitorlist':{'monitorId':'5b30a4002dea1a0fd6597b79'}}})

1 个答案:

答案 0 :(得分:0)

将变量从监视列表更改为监视列表可以解决此问题,谢谢。