0

出版商:

Meteor.publish('market', function(limit) {
  let self = this;

  Markets.find({}, {
    limit: limit
  }).observeChanges({
    added: function(id, market){
      self.added("market", id, market);

      let country = findCountry(market);
      self.added("countries", country._id, country);
    }
  });

  return self.ready();

});

上面的发布者工作正常。我的问题是上述发布者发布market和相关countries光标。市场光标有限制。现在我想发布有限制的市场光标,并且应该无限制地运行observeChangescountry

所以我写了像

Meteor.publish('market', function() {
  let self = this;

  let markets = Markets.find({}, {
    limit: limit
  });

  Markets.find().observeChanges({
    added: function(id, market) {

      let country = findCountry(market);
      self.added("countries", country._id, country);
    }
  });

  return [self.ready(), markets]; // How to publish multiple cursors??

});

如何发布多个游标?

4

1 回答 1

0

看起来很好地使用了reywood:publish-composit包。当添加、更新或删除新记录时,它会处理相关文档的所有逻辑。

我不确定你的findCountry函数中的逻辑是什么,但我想它会是这样的:

Meteor.publishComposite('market', {
    find: function() {
        return Markets.find({}, {limit: limit});
    },
    children: [
        {
            find: function(market) {
                return Countries.find({countryCode: market.countryCode});
            }
        }
    ]
});
于 2016-01-08T06:47:31.867 回答