【问题标题】:Meteor: Reactivity in publications with nested mongo queriesMeteor:具有嵌套 mongo 查询的出版物中的反应性
【发布时间】:2016-11-16 14:42:34
【问题描述】:

我有一个这样的收藏:

//Groups Collection
{
  _id:1,
  members: [
    {
      memberId: 'A1B2',
      content: [1,2,3]
    },
    {
      memberId: 'C10B',
      content: [4,5,6]
    }
  ]
},
{
  _id:2,
  members: [
    {
      memberId: 'A1B2',
      content: [7,8,9]
    },
    {
      memberId: 'F804',
      content: [10,11,12]
    }
  ]
}

还有另一个像这样的集合:

//Users Collection
{
    _id: 'A1B2',
    name: 'Newton'
},
{
    _id: 'C10B',
    name: 'Gauss'
},
{
    _id: 'F804',
    name: 'Leibniz'
}

我需要一个发布,其中包含 _Id = 1 的 Groups 数组中所有用户的 id。我试过了:

Meteor.publish('themembers',idGroup,function() {
    return Users.find({_id:{$in:Groups.findOne(idGroup).members.map(function(e) {return e.memberId})}});
});

然后我订阅:

Template.problem.onCreated(function() {
    Meteor.subscribe('themembers',1);
});

现在我可以访问助手中的成员了:

Template.problem.helpers({
    members: function() {
        return Users.find();
    }
});

助手也可以正常工作。

但是现在,如果我向群组添加新成员,它不会出现在列表中,...我的订阅似乎没有反应。

我做错了什么?

【问题讨论】:

标签: meteor collections publish subscribe


【解决方案1】:

Meteor 的典型问题:

你应该看看peerlibrary:reactive-publish

https://github.com/peerlibrary/meteor-reactive-publish

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-27
    • 1970-01-01
    • 2015-02-23
    • 1970-01-01
    • 2019-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多