Meteor嵌套出版物

时间:2017-04-14 20:16:19

标签: meteor

我在Meteor中有两个集合AB。对于A我有一个出版物,我在A过滤掉了一系列文件。现在,我想为B创建一个发布,我在B中发布所有与B.length匹配的A.length字段的文档。

我无法找到显示此示例的任何示例,但我觉得它必须是标准用例。怎么能在Meteor中完成?

2 个答案:

答案 0 :(得分:1)

这是reywood:publish-composite

的常见模式

从'meteor / 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,而不是合成的单个集合A,它有一些B的字段。后者更多就像一个SQL JOIN。

答案 1 :(得分:0)

使用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
      }
    })
});
相关问题