2017-05-31 182 views
0

我有以下代码呈现集合中currentUsers的文档。但是,我希望属于同一组织的管理员也能够查看和编辑该集合。 this.user.profile.organization不起作用。那么,我将如何让这个对象可以被管理员从属于同一个组织。生成的文件获取当前用户的组织。服务器端流星this.userprofile

Meteor.publish('skills', function skillsPublication() { 
    return Skills.find({ 
     owner: this.userId, 
    }); 
}); 

回答

1

当您在服务器上时,您始终可以从MongoDB数据库查询用户文档。

Meteor.publish('skills', function skillsPublication() { 
    const user = Meteor.users.findOne({ _id: this.userId }) 
    // now you can do user.profile.organization 

    return Skills.find({ 
    $or: [ 
     { owner: this.userId }, 
     { organization: user.profile.organization } 
    ] // returns a document owned by the user or owned by the user's organization 
    }) 
}) 

刚一说明,流星建议不要使用您的用户收集.profile领域,因为该领域总是发布到客户端。流星建议您改为在用户文档上使用顶级密钥。

欲了解更多信息,请阅读:https://guide.meteor.com/accounts.html#dont-use-profile