【问题标题】:$pull from 2 array fields in a mongo collection$pull 从 mongo 集合中的 2 个数组字段
【发布时间】:2014-11-03 07:41:09
【问题描述】:

是否可以从文档中的 2 个数组字段中提取 $pull:例如,如果我有如下所列的文档:

{
  "_id" : "376123123731223812312376",
  "array1" : [{
      "field1" : "0000000",
      "field2" : 1,
      "field3" : "foo1"
    }],
  "createdat" : 1411068136599,
  "updatedat" : 1413198791350,
  "array2" : ["value1","value2"]
}

我可以做类似的事情吗:

var update  = {'$pull':{'array1':{'field1':'0000000'},'array2':{"value2"}}};

上面给出了一个语法错误,所以我想知道它是否可以完成?

【问题讨论】:

    标签: arrays mongodb field pull


    【解决方案1】:

    好的,所以我发现我使用了错误的符号。 array2 只是一个字符串数组,所以解决方案是

    var update = {'$pull':{'array1':{'field1':'0000000'},'array2':"value2"}};

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      • 2021-03-10
      • 2015-01-31
      • 2021-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多