【问题标题】:Meteor.publish on server doesn't show new documents on client服务器上的 Meteor.publish 不在客户端显示新文档
【发布时间】:2016-04-28 07:17:52
【问题描述】:

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

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

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

感谢您的帮助!

【问题讨论】:

    标签: javascript meteor publish-subscribe mongo-collection


    【解决方案1】:

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

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

    但是这种解决方案有一个缺点:群组文档也会被发布。所以,也许你应该从中排除一些字段。

    【讨论】:

      猜你喜欢
      • 2012-12-22
      • 2018-03-03
      • 2021-11-20
      • 2021-09-04
      • 2017-09-30
      • 2014-08-26
      • 2013-03-24
      • 2019-01-08
      • 2013-03-18
      相关资源
      最近更新 更多