Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mongodb meteor出版物中的反应式查询结果?_Mongodb_Meteor_Meteor Publications - Fatal编程技术网

Mongodb meteor出版物中的反应式查询结果?

Mongodb meteor出版物中的反应式查询结果?,mongodb,meteor,meteor-publications,Mongodb,Meteor,Meteor Publications,本出版物的目标是发布团队已“解锁”并满足其先决条件的问题。它工作正常,但在团队解决其他问题(添加到team.solved字段)时,发布不会进行反应性更新 我发现这是因为团队的结果。findOne({});查询不会进行反应性更新,因此team.solved字段永远不会更改。是否有更好的设计允许它进行反应式更新,或者我必须将其更改为Teams.find()并使用.observeChanges() 如果我在这里使用任何不寻常的约定,请让我知道。有一些不同的包设计来解决这些类型的问题,reywood:p

本出版物的目标是发布团队已“解锁”并满足其先决条件的问题。它工作正常,但在团队解决其他问题(添加到team.solved字段)时,发布不会进行反应性更新

我发现这是因为团队的结果。findOne({});查询不会进行反应性更新,因此team.solved字段永远不会更改。是否有更好的设计允许它进行反应式更新,或者我必须将其更改为Teams.find()并使用.observeChanges()


如果我在这里使用任何不寻常的约定,请让我知道。

有一些不同的包设计来解决这些类型的问题,reywood:publish composite和peerlibrary:Responsive publish出现在我的脑海中

要使用peerlibrary:reactive publish实现这一点,它在语法上要简单得多,您只需将代码包装在自动运行中,如下所示:

Meteor.publish("problems", function () {
    this.autorun(function() {  

      if(!this.userId) return [];

      var user = Meteor.users.findOne(this.userId);

      if(!user.profile.team) return [];

      var team = Teams.findOne({_id:user.profile.team});

      return Problems.find({requirements: {$not: {$elemMatch: {$nin: team.solved}}}});

    });
});

Meteor.publish("problems", function () {
    this.autorun(function() {  

      if(!this.userId) return [];

      var user = Meteor.users.findOne(this.userId);

      if(!user.profile.team) return [];

      var team = Teams.findOne({_id:user.profile.team});

      return Problems.find({requirements: {$not: {$elemMatch: {$nin: team.solved}}}});

    });
});