1

问题是服务器上的下一个代码:

Meteor.publish(null , function() {
    let events = [];
    Groups.find({participants: this.userId}).forEach(function(item) {
        events.push(item.latestEvent);
    });
    return Events.find({_id: {$in: events}});
});

> Events.find().fetch() 在不重新加载页面的情况下,无法在客户端上查看新文档。

两个集合都在lib文件夹中:

Groups = new Mongo.Collection('groups');
Events = new Mongo.Collection('events');

我很确定问题出在反应性数据源中,但仍然无法解决。

谢谢你的帮助!

4

1 回答 1

0

是的,你是对的:只有 Events 集合是响应式的。有一种简单的方法可以使用publish-composite包来解决它:

Meteor.publishComposite(null, {
    find(){
      return Groups.find({participants: this.userId});
    },
    children: [{
      find(group){
         return Events.find({_id: {$in: group.latestEvent}});
      }
    }]
});

但是这个解决方案有一个缺点:组文档也会被发布。因此,您可能应该从中排除一些字段。

于 2016-05-01T15:31:28.373 回答