meteor - How to only subscribe to database updates (without fetching)? -
i have large database , want send actual data updates client.
not want each client fetch whole set of data done natively meteor's pub/subs.
tried ground:db
still fetched data.
how can achieve this?
to achieve can observechanges
on whole collection , channel changes (added
, changed
, removed
) each publication handler.
a rough application :
var pubhandlers = [] meteor.publish('changes stream', function handlepublication() { pubhandlers.push(this) this.onstop(() => pubhandlers.splice(pubhandlers.indexof(this), 1) ) this.ready() }) mycollection.find().observechanges({ added : function docadded(id, doc) { for(let pubhandler of pubhandlers) { pubhandler.added('my collection', id, doc) } }, changed : function docchanged(id, fields) { for(let pubhandler of pubhandlers) { pubhandler.changed('my collection', id, fields) } }, removed : function docremoved(id) { for(let pubhandler of pubhandlers) { pubhandler.removed('my collection', id) } } })
note in case docremoved
throw if document didn't exist on client.
in case, updates on collection sent subscribed clients. may want use smartly distributed mongo.cursor
share load in cleaner way.
Comments
Post a Comment