2017-02-07 9 views
2

私はmeteorhacksを使用して、いくつかのデータを公開しようとしている:集計:私のテンプレートIでmeteorhacks:集計エラー

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

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() 
}); 

私は2つのコレクションを持って、一つは、集約されたデータを格納しますデータを購読する:

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

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

     }, 300) 
    }) 

}) 
}); 

クロムコンソールで次のエラーが表示されます。

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

Meteorパブリケーションでは、Meteorメソッドでのみ集計を使用することはできません。この問題を回避するには、packageを使用することを検討してください(免責事項:私は著者です)。

+0

まあ、奇妙なことは、それがこのように動作するように使用されているものである...しかし、どういうわけか、私はコピー私のファイルを新しいフォルダに移動し、突然このエラーが発生しました。私はこれを行うために[this](http://joshowens.me/using-mongodb-aggregations-to-power-a-meteor-js-publication/)ガイドを使用しました。 –

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); 

});