Meteor用户发现没有在发布中返回

时间:2014-12-04 17:16:06

标签: mongodb meteor

我试图返回带有组织ID的流星用户,但我没有收到任何回复。

Meteor.publish('organizationsUsers', function() {
    var user = Meteor.users.findOne(this.userId);
    return Meteor.users.find({organizationId: user.organizationId});
}); 

我的路由器

Meteor.subscribe('organizationsUsers');

视图

organizationsUsers: function() {
        if (!this.users)
            return;
        return Meteor.users.find(); // {}, {sort: {createdAt: -1}}
    }

在我的模板中我有

{{#each organizationsUsers}}
{{> userItem}}
{{/each}}

在JS中

organizationsUsers: function() {
        if (!this.users)
            return;
        return Meteor.users.find(); // {}, {sort: {createdAt: -1}}
    },

2 个答案:

答案 0 :(得分:0)

如果要返回游标,则不应在发布函数中执行多个查询或连接,而是执行以下操作:

// CLIENT
Tracker.autorun(function () {
  if (Meteor.userId()) {
    if (typeof organizationId === 'string') {
      Meteor.subscribe('organizationsUsers', Meteor.user().organizationId);
    } else {
      console.log('error');
      // if necessary, debug why organizationId is not a string
    }
  }
});

// SERVER
Meteor.publish('organizationsUsers', function(organizationId) {
  check(organizationId, String);
  return Meteor.users.find({organizationId: organizationId});
}); 

答案 1 :(得分:0)

想出了这个问题,首先我使用了与在org(Meteor Publish and MongoDB)中使用userId数组的发布函数相同的代码。蒙戈文对于模板,我有以下内容:

organizationsUsers: function() {
    if (!this.users)
         return;
          return Meteor.users.find(); // {}, {sort: {createdAt: -1}}
}

if语句包含了问题,这项工作

 organizationsUsers: function() {
    return Meteor.users.find(); // {}, {sort: {createdAt: -1}}

}