I this possible to publish multiple collections in single subscription call? if so please guide me.
How to publish multiple collections in single subscription call in meteor?
Asked Answered
Please edit your question and add a code snippet you tried to use. It would help people answering your question greatly! Read more about how to ask a great question. –
Idol
@methode. Thanks mate. I will follow –
Aleasealeatory
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.
Instead of returning an array, you also could create a "virtual" collection which you setup in your own publishing method. To filter those docs you are able to use arguments on publish/subscribe. If you just want to have complex documents to display content this may a smart solution. If you want to use the collection also for updates on db, an array result is mostly easier to implement. Cheers, Tom –
Tamar
© 2022 - 2024 — McMap. All rights reserved.