For me it seems that method is reactive other way - it reevaluate when you change it’s arguments.
Not that it would return output of collection.
And also this way using collection return to client would be very network heavy.
I use this way on my reports generator.
I do any calculations on the method before send the result to the client, so have any solution for this???
Thanks for your helping.
Well, you can still call method to update data and react on it’s callback by doing action you want.
Rendering template, or changing reactive variable and than using that variable in helper and template something like this pseudocode:
But to better help we would need to know usecase. What exactly you want to do after the method is finished.
If you need to subscribe, or what is the expected action.
Reports are normally run against a snapshot in time (end-of-day, end-of-month, etc). You do not need reactive data for this use case and a (static) method call is fine.
On the other hand, if you are wanting to display information as data changes, then you do need reactive data, and as @shock says, pub/sub is the way to go.
If you want a reactive, pub/sub model, which requires transformed data, then you should look at collection transforms and/or collection hooks. One or other of these may allow you to manipulate your collection results for your reporting, while still giving you reactive updates.
// This assumes "Collection" has already been defined as a global object (Collection = {})
// and is to conform with your own examples.
Collection.Customer = new Mongo.Collection('customer', {
transform: function(doc) {
... extend doc here ...
return doc;
}
});
But my report (payment report) have conditions with many collections such as category, item, order, payment. So I need to pub/sub all of collectiona and then do …
You can aggregate the data and then provide it inside you publish method with this.added
Client:
Reports = new Mongo.Collection('reports', null) // null means only client side Collection
Meteor.subscribe('reports-publication', 'someId')
Server: inside a publish method
Meteor.publish('reports-publication', function(id) {
var oneFoo = Foo.findOne(id);
var someBars = Bars.find({fooId: oneFoo._id}).fetch();
oneFoo.bars = someBars;
// Here we inform the subscription to add oneFoo to the ClientSide Reports Collection
// But it has a new field in it, bars!
this.added('reports', oneFoo._id, oneFoo);
});