Remove sub-document from Mongo with mongoose

后端 未结 6 548
情歌与酒
情歌与酒 2020-12-16 01:12

I am trying to remove an item from a collection that is stored in a mongoose document. My document looks like this:

{
  \"__v\": 3,
  \"_id\": \"5221040475f         


        
6条回答
  •  悲哀的现实
    2020-12-16 01:54

    Subdocuments now have a remove function. Use as follows from the spec:

    var doc = parent.children.id(id).remove();
    parent.save(function (err) {
      if (err) return handleError(err);
      console.log('the sub-doc was removed')
    });
    

提交回复
热议问题