Ramesh Murugesan
Ramesh Murugesan

Reputation: 5013

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

I this possible to publish multiple collections in single subscription call? if so please guide me.

Upvotes: 9

Views: 6271

Answers (1)

David Weldon
David Weldon

Reputation: 64312

Yes. A publish function can return an array of cursors. For example:

client

Meteor.subscribe('roomAndMessages');

server

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

important note

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.

Upvotes: 18

Related Questions