suppose I have this kind of data...
data = [{
"_id" : "1",
"parentId" : "thisPostId",
"topLevelId" : "1",
"text" : "<p>comment</p>",
},
{
"_id" : "2",
"parentId" : "1",
"topLevelId" : "1",
"text" : "<p>reply to comment</p>",
},
{
"_id" : "3",
"parentId" : "2",
"topLevelId" : "1",
"text" : "<p>reply to reply to comment</p>",
},
{
"_id" : "4",
"parentId" : "3",
"topLevelId" : "1",
"text" : "<p>reply to reply to reply to comment</p>",
}]
I need to remove a comment and all of its child...
if comment to remove is _id:1
,, then I need an array of ["1","2","3","4"]
,,, then i can run Coll.remove({_id:{$in:["1","2","3","4"]}}, callback);
if comment to remove is _id:2
,, then I need an array of ["2","3","4"]
if comment to remove is _id:3
,, then I need an array of ["3","4"]
if comment to remove is _id:4
,, then I need an array of ["4"]
I tried this (with no idea)...
_.forEach(data, function(value, key){
_.pluck(_.where(key, { "parentId" : "2" }), '_id');
});
and not working...
any help with javascript/lodash/underscore will be appreciated,,,
thank You...