How to delete nested array of object based on id

JPGg
How to delete particular object in illustrations array based on articleId and randomid
I tried like this

var dirName = SERVER_DIR + userId + '/articles/'+articleId+'/Illustrations/'+image; 
let data={
        imagePath:dirName,
        title:req.body.title
    }
Collections.user.update({article:{$elemMatch:{articleId:req.body.articleId}},"article.$.content.illustrations":{$elemMatch:{randid:req.body.randid}}},{ $pull: 
        {"article.0.content.0.illustrations":data}},
        function(err,result){
         if(err)
         res.send(err)
         else
         res.send("Deleted");
         console.log(result);
     })
Collections.user.update(
  { "article.articleId": req.body.articleId} },
  { $pull: { article: { content: { illustrations: { $elemMatch: { randid: req.body.randid } } } } } },
  { multi: true },   // if you have multiple articleId and randid in your array, remove otherwise
  function(err,result) {
    if(err)
      res.send(err)
     else
       res.send("Deleted");
})

source : https://docs.mongodb.com/manual/reference/operator/update/pull/#pull-array-of-documents

MongoDB only works with 1 level array elements. Your command will remove an item in article array (first level), not the element of illustrations array (level 3).
I think @prudhviraj should re-design the database, use multiple collections instead embeded documents.

Well, @lc3t35’s solution should work to modify the database, but then you might run into the issue of Meteor’s reactivity not working for nested arrays of objects.
I’d go with @minhna’s solution if at all possible.

Thanks for your reply. It is working. But If i tried like this, it removes entire object of illustrations array. But i need to pull only randomid in illustrations array.

can you give an example of the result of my solution (before/after) and what you expect (as after) ?