如何在流星的单个订阅调用中发布多个集合?

How to publish multiple collections in single subscription call in meteor?

我可以在单个订阅调用中发布多个集合吗?如果是这样,请指导我。

是的。 publish 函数可以 return 游标数组。例如:

客户端

Meteor.subscribe('roomAndMessages');

服务器

Meteor.publish("roomAndMessages", function (roomId) {
  check(roomId, String);
  return [
    Rooms.find({_id: roomId}),
    Messages.find({roomId: roomId})
  ];
});

重要说明

If you return multiple cursors in an array, they currently must all be from different collections. We hope to lift this restriction in a future release.