mongodb - Meteor reactive publish data from different collections -
i try build homeautomation system meteor. therefore following thing.
i have collection different livevalues i'm reading kind of source. each document value of example sensor actual value.
now want create second collection called thing. in collection i'd add "things" example "roomtemperature living" data thing. 1 attribute should connection 1 of livevalues.
now want publish , subscribe meteor thing collection, because on webinterface doesn't matter livevalue behind thing.
here, in optionen, complicated part starts.
how can publish data client , have reactive update when livevalue has changend thing? because it's differnt collection "thing" collection.
in idea via 1 subscrition 1 "thing" document , subscription update of livevalue of livevalue collection.
is workable?
has idea how can handle this?
i've heard meteor-reactive-publish i'not sure if solution. i've heard needs lots of power server.
thanks help.
so want merge documents on server side 1 reactive collection on client-side.
you should use observechanges
provided meteor collections described in docs.
by can observe changes on server side collections , publish client-side aggregated collection, this:
// data kind of sensor var cursor = somesensor.find({/* query */}); var self = this; // observe changes in cursor , publish // 'things' collection in client var observer = cursor.observechanges({ added: function (document) { self.added('things', document._id, document); }, removed: function (document) { self.removed('things', document._id, document); }, changed: function (document) { self.changed('things', document._id, document); } }); // make publication ready self.ready(); // stop observer on subscription stop self.onstop(function () { observer.stop(); });
with things
collection have data sensors reactively.
hope helps you.
Comments
Post a Comment