MongoDB Update (Insert a List of Item to an Array)

后端 未结 5 1737
滥情空心
滥情空心 2021-01-02 16:12

I want to add several items to arrays of several rows in Mongo. How can I do this?

I want to start with this:

{\'x\': \'h\', arr: [1,2,3] }
{\'x\':          


        
5条回答
  •  滥情空心
    2021-01-02 16:27

    the simplest approach is by using a conventional update operation

      db.urColl.update(
        { x: "h" },
        { $push: { arr: { $each: [6,8] } } },
        { multi: true }
      );`
    

提交回复
热议问题