我需要创建一个出版物,它为我提供了集合中的一组文档。在这里,您可以看到这些文档是如何相互关联的:
{
"_id" : "peRuJcPMDzZgTvWSX",
"author" : "author",
"type" : "article",
"parent" : "mnfTFfZ7Fqcu6ZJ7T",
"ancestors" : [ "hbSycmNNvmdqvpchX", "mnfTFfZ7Fqcu6ZJ7T" ]
}
{
"_id" : "mnfTFfZ7Fqcu6ZJ7T",
"article" : "article",
"parent" : "hbSycmNNvmdqvpchX",
"ancestors" : [ "hbSycmNNvmdqvpchX" ]
}
{
"_id" : "hbSycmNNvmdqvpchX",
"title" : "title",
"ancestors" : [ ]
}
所以我知道的是第一个文档的 ID,我还需要出版物中的所有祖先。
Meteor.publish('list', function(id) {
check(id, String);
return Collection.find({}); // WRONG: gives me ALL documents
return Collection.find({ _id: id }) // WRONG: gives me only the first document (main)
// NEEDED: Main document and all ancestors
});