【问题标题】:meteorhacks:aggregate error流星黑客:聚合错误
【发布时间】:2017-02-07 20:44:42
【问题描述】:

我正在尝试使用 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 aggregate publish-subscribe


    【解决方案1】:

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

    【讨论】:

    • 嗯,奇怪的是它以前是这样工作的……但不知何故,我将我的文件复制到了一个新文件夹中,突然出现了这个错误。我使用this 指南来做到这一点。
    【解决方案2】:

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

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

    应该是:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      • 2019-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多