是什么导致 non-Cursor 的流星阵列(流星中的 DDP)

what causing meteor array of non-Cursor (DDP in meteor)

只是一个简单的问题。

我有一个使用聚合的发布示例。

Meteor.publish('tags', function(tag){
    var sub = this;
    var pipeline = [
        {$project: {tags:1, author: 1, title:1, permalink:1 }},
        {$unwind:"$tags"},
        {$match: {"tags": tag}}];
    var results = Posts.aggregate(pipeline);
    var arrayLength = results.length;
    for(var i=0; i < arrayLength; i++){
          var tags = results[i];
          sub.added('posts', Math.random(), tags);
    }
    sub.ready();
});

为什么我需要一个额外的循环来存储 collection 帖子中的数据。

for(var i=0; i < arrayLength; i++){
   var tags = results[i];
   sub.added('posts', Math.random(), tags);
}
sub.ready();

如果我 return 结果不包括 sub.added 的循环,我将在我的客户端命名空间上得到 non-Cursor 错误数组。

就我而言,

此代码

sub.added('posts', Math.random(), tags);

我们只是说 DDP 是用 id = Math.random() 记录它,fields = tags 被添加到帖子集合中。 ddp 用于绑定客户端和服务器,它应该在我们订阅(客户端应用程序)时传输给客户端。

流星平台示意图:

一旦 meteor 应用程序创建,ddp 就已经是默认包了。