Push to two separate arrays in one update call in mongodb

后端 未结 1 1263
爱一瞬间的悲伤
爱一瞬间的悲伤 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)
提交回复
热议问题