2016-04-03 32 views
0

我想创建一个页面,显示属于我的同一组织的数据库中的所有用户。发布属于与登录用户相同组织的Meteor用户?

我的用户存储如下:

Accounts.createUser({ 
    email: email, 
    password: password, 
    profile:{ 
     firstName: first, 
     lastName: last, 
     type: "Member", 
     organization: organization, 
     created: date 
    } 
}); 

我知道我必须给用户发布到我的用户列表组件,和我挣扎搞清楚如何只发布其profile.organization匹配的用户已登录的用户profile.orgainzation。

这将返回所有用户,因为它应该,我得到了那么远:

return Meteor.users.find(); 

我试着用你在这里看到一个代码块,但它不工作,可能出于多种原因,它甚至抛出一个错误,说我不能使用Meteor.user()服务器端,我必须使用this.user()...但没有工作,要么:

return Meteor.users.find({ 

    profile:{ 
     organiztion: Meteor.user().profile.organization 
    } 

}); 

我不知道从这往哪儿走。任何帮助将不胜感激!

回答

0

我认为这可能工作(未经测试)。这是一个服务器端功能。

Meteor.publish("organizationUsers", function() { 
    if (this.userId) { 
    var user = Meteor.users.findOne(this.userId); 
    var org = user.profile.organization; 
    return Meteor.users.find({'profile.organization': org}); 
    } 
}); 

客户端,您可以筛选您希望的用户(不包括当前用户):

Meteor.users.find({'profile.organization': org, '_id' : {$not : Meteor.userId()}}); 
+0

你的先生是个天才。非常感谢,服务器端工作。我真的想限制它的服务器端,以便其他组织中的其他人无法访问(如果他们想)访问来自不同组织的用户。 – TyGoss

相关问题