Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 950
Ramesh Murugesan Avatar asked Jul 06 '15 05:07

Ramesh Murugesan


1 Answers

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.

like image 62
David Weldon Avatar answered Oct 06 '22 23:10

David Weldon