流星套装出版物

问题描述:

我在流星有两个集合AB。对于A我有一个出版物,我在A中筛选出一系列文档。现在我想为B创建出版物,其中我发布了B中的所有文档,其中的字段B.lengthA.length匹配。流星套装出版物

我一直没有找到任何示例,显示这个,但我觉得它必须是一个标准的用例。这怎么可能在流星中完成?

使用serverTransform

Meteor.publishTransformed('pub', function() { 
    const filter = {}; 
    return A.find(filter) 
    .serverTransform({ 
     'B': function(doc) { 
     return B.find({ 
      length: doc.length 
     }); //this will feed directly into miniMongo as if it was a seperate publication 
     } 
    }) 
}); 

这是从 '流星/ reywood:发布复合' 为reywood:publish-composite

进口{publishComposite}共同的图案;

publishComposite('parentChild', { 
    const query = ... // your filter 
    find() { 
     return A.find(query, { sort: { score: -1 }, limit: 10 }); 
    }, 
    children: [ 
     { 
      find(a) { 
       return B.find({length: a.length }); 
      } 
     } 
    ] 
}); 

这比serverTransform一个完全不同的图案作为你结束了两个集合,A和B在客户机上,而不是具有的B的某些字段的合成单个集合的后者更像一个SQL JOIN。