Another option is to use the Meteor Stream package , whose purpose is to avoid using the server-side mongodb collection. It supports client-to-client, server-to-client, client-server and server-to-server messaging, including Meteor Cluster support
If you want to stay with the meteorite only through collections, the following code allows you to either send a message from the client to all clients, or a message from the server to all subscribers. Just use this mechanism to then run the function on the client side after receiving the correct message. The code is executed in such a way that you will never have any unnecessary items left in the collection.
Messages = new Meteor.Collection("messages"); if (Meteor.isClient) { Meteor.subscribe("messages"); var query = Messages.find({}); var handle = query.observe({ added: function(document) { console.log(document.message); } });
Flavien volken
source share