Push items into mongo array via mongoose

前端 未结 8 1566
小鲜肉
小鲜肉 2020-11-22 03:22

I\'ve scoured SO a good bit looking for the answer but I\'m sure that I\'m lost for the right words to describe what I\'m after.

Basically I have a mongodb collection

8条回答
  •  礼貌的吻别
    2020-11-22 04:16

    An easy way to do that is to use the following:

    var John = people.findOne({name: "John"});
    John.friends.push({firstName: "Harry", lastName: "Potter"});
    John.save();
    

提交回复
热议问题