Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 流星黑客:聚合错误_Meteor_Aggregate_Publish Subscribe - Fatal编程技术网

Meteor 流星黑客:聚合错误

Meteor 流星黑客:聚合错误,meteor,aggregate,publish-subscribe,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, nasch

我正在尝试使用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)

我做错了什么?

您不能在Meteor出版物中使用聚合,只能在Meteor方法中使用聚合。为了解决这个问题,你可以考虑使用这个(免责声明:我是作者)。

< P>我的坏…我发现我的错误:

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

_.each(nascholingenOverzicht, function(parent){

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

});

嗯,奇怪的是,它以前是这样工作的……但不知怎么的,我把我的文件复制到了一个新文件夹,突然出现了这个错误。我用向导来做这件事。