【问题标题】:i want to find an field in collection and also want to find an object id in array and push more object in sub array我想在集合中找到一个字段,也想在数组中找到一个对象 id 并在子数组中推送更多对象
【发布时间】:2016-06-16 13:20:27
【问题描述】:

Mongo DB 集合是

{ 
  findId: xyz,
  mainArray:[{
            andFindThisObjectId:abc,
            pushInThisArray:[{newValue,anotherValue}}
  }]
}

所以在这里我想在 pushInThisArray 字段中找到并推动更多价值

【问题讨论】:

  • {newValue,anotherValue} 不是有效的 BSON?请详细说明您的问题...
  • pushInThisArray:[{newValue,anotherValue}} => pushInThisArray:[{newValue,anotherValue}]

标签: arrays node.js mongodb mongoose mongodb-query


【解决方案1】:
db.collection.update({
                  $and:[{"findId":"BL0303160"},
                        {"mainArray._id":ObjectId("56d7a674af6cb08406f3bf8a")}
                       ]},
                  {$push:{
                          "mainArray.$.pushInThisArray":
                                      {"myName":"Pratik", 
                                        "myPc":"HP"}
                  }});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-27
    • 1970-01-01
    • 1970-01-01
    • 2013-10-07
    • 2019-05-28
    • 2018-07-02
    • 2019-09-25
    • 1970-01-01
    相关资源
    最近更新 更多