Hi,
I need some help to resolve this issue.
Basically I want to show in the UI a list of items coming from a MongoDb collection.
As the collection has multiples items for the same “ID”, I need to do an aggregation to select the higher one.
My problem is the view doesn’t update if I change any parameter of this collection.
The implementation is:
- View:
{{#each getList}} {{ID}} {{version}} {{dataexample}} {{/each}}
- Client side
Template.example.helpers({
‘getList’: function() {
return ReactiveMetod.call(‘listItems’);
}
});
- Server side
Meter.methods({
‘listItems’: function(){
var final = [];
var pipeline = [{
$group: {
"_id": “$ID”,
version: {$max: “$version”}
}
}];
var result = CollectionItems.aggregate(pipeline); result.forEach(function(entry) { final.push( CollectionItems.findOne({ ID: entry._id, version: entry.version }) ); }); return final;
});
So if something change of this collection, it doesn’t update the view.
I was thinking to force reload every 5 seconds but I was expecting to find a way to keep the reactivity/multicollaboration in realtime.
Many thanks