mongoose. updating embedded document in array

前端 未结 3 670
鱼传尺愫
鱼传尺愫 2021-01-02 05:06

In the a official mongoose site I\'ve found how can I remove embedded document by _id in array:

post.comments.id(my_id).remove();
post.save(function (err) {
         


        
3条回答
  •  無奈伤痛
    2021-01-02 05:47

    You could do

    var comment = post.comments.id(my_id);
    comment.author = 'Bruce Wayne';
    
    post.save(function (err) {
        // emmbeded comment with author updated     
    });
    

提交回复
热议问题