Why mango aggregation does not respond to meteor

Meteor newb here. The reactivity of the Meteor puzzles me. I can update the collection from the Mongo console and it will instantly update the user interface. But not with a mango aggregate?

I use meteorhacks: aggregate to get mongo aggregate () loaded into the meteor.

Aggregation works great. I can immediately see the data update in the mongo console. However, if I show it in the user interface, there is no update even when updating the client.

db.collection:

{a:1,b:2}
{a:1,b:2}

The code:

inputCollection = new Meteor.Collection('input_collection')
outputCollection = new Meteor.Collection('output_collection')

Meteor.methods({
    pleaseAggregate: function() {
      inputCollection.aggregate([{
        $group : {
            _id : "$a",
            count: { $sum: 1} //should return 2 with the sample data above
        }
      },
      {$out : "output_collection"}
       ]);
    }
});

HTML

<p>Aggregates: {{agg.count}}</p>

Client.js

Template.debug.helpers({
 agg: function() {
    return outputCollection.find().fetch()[0]
  }
});

By the way, it is published, I have "unsafe" installed.

I'm missing something obvious for a meteor, I think. What is it?

+4
source share
2 answers

1.1.0.2. $out Mongo aggregate .

, , :

results = Collection.aggregate([{
        $group : {
            _id : "$a",
            count: { $sum: 1} //should return 2 with the sample data above
        }
   }]);

OtherCollection.insert(results);
0

, , , . .

0

Source: https://habr.com/ru/post/1599588/


All Articles