This is an example of documents which are assigned together by a parent-field:
{
"_id" : "dUgyVgoxVhYOU0wZC",
"title" : "section-title",
"type" : "section",
"parent" : "I5ChGoVOeU2BKsgvZ"
}
{
"_id" : "G3ecqJxydXJnFvRhN",
"title" : "group-title",
"type" : "group",
"parent" : "dUgyVgoxVhYOU0wZC"
}
{
"_id" : "djM5IU2wmOhpGoBX8",
"title" : "elemtn-title",
"type" : "element",
"parent" : "G3ecqJxydXJnFvRhN"
}
Now I need all the docs, which are assigned together. My attempt:
var id = "dUgyVgoxVhYOU0wZC";
Meteor.publish('article', function(id) {
return Articles.find({
$or: [
{ _id: id },
{ parent: id }
]
});
});
But this just goes to the second level. But I also need the third level for which I don't have the direct access (id or parent)
Update
I tried to do that with publishComposite
, but my attempt doesn't work:
Meteor.publishComposite('article', function(id){
return {
find: function(){
return Articles.find({
$or: [
{ _id: id },
{ parent: id }
]
});
},
children: [{
find: function(element){
return Article.find({ parent: element._id });
}
}]
}
});