Push to two separate arrays in one update call in mongodb

后端 未结 1 1267
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-01 18:37

I am trying to update to update two separate arrays in a document with one update call. Is there a way to do this?

For example if I have a document like:

<         


        
1条回答
  •  鱼传尺愫
    2020-12-01 18:57

    You can specify multiple fields to the $push operator

    db.collection.update(
       { _id :1 }, 
       { $push : { array1 : "1",   array2 : "5" }}
    )
    

    0 讨论(0)
提交回复
热议问题