meteorhacks:汇总错误

时间:2017-02-07 20:44:42

标签: meteor aggregate publish-subscribe

我正在尝试使用meteorhacks发布一些数据:aggregate:

Meteor.publish('alleNascholingen',function() {
var self = this;

var nascholingenOverzicht = nascholingenCollectie.aggregate([
   //{$match: {creatorId: this.userId}},
   //{$project: {naam: 1, familienaam:1, nascholingen:1}},
   { $unwind : "$nascholingen" },
   { $sort: {
       "nascholingen.inschrijfMoment": -1
   }}
   ]);

_.each(nascholingenOverzicht, function(parent){
    _.each(parent, function(child){
        self.added('selectie', child._id, child);
    });
});


 self.ready()
});

我有两个集合,一个用于存储聚合数据:

nascholingenCollectie = new Mongo.Collection('nascholingen');
nascholingenSelectie = new Mongo.Collection('selectie');

在我的模板上,我订阅了数据:

Template.nascholingBeheer.onCreated(function() {
let self = Template.instance();

    self.subscribe('alleNascholingen', function () {
        setTimeout(function () {

        }, 300)
    })

})
});

我在Chrome控制台中收到以下错误:

collection.js:173 Uncaught Error: Expected to find a document to change
at Object.update (http://localhost:3000/packages/mongo.js?hash=c4281c0ff989ebee020f59f5a7b0735053cea5f7:246:29)
at Object.store.(anonymous function) [as update] (http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:3613:48)
at http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:4441:19
at Array.forEach (native)
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:149:11)
at http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:4440:13
at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?hash=cde485f60699ff9aced3305f70189e39c665183c:157:22)
at Connection._performWrites (http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:4437:9)
at Connection._flushBufferedWrites (http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:4423:10)
at Connection._livedata_data (http://localhost:3000/packages/ddp-client.js?hash=bc32a166cd269e06a394f9418e0024d805bab379:4391:12)

我在这里做错了什么?

2 个答案:

答案 0 :(得分:1)

您不能在Meteor出版物中使用聚合,仅在Meteor方法中使用。要解决此问题,您可以考虑使用此package(免责声明:我是作者)。

答案 1 :(得分:1)

我的坏......我发现了我的错误:

_.each(nascholingenOverzicht, function(parent){
_.each(parent, function(child){
    self.added('selectie', child._id, child);
});
});

应该是:

_.each(nascholingenOverzicht, function(parent){

    self.added('selectie', parent._id, parent);

});