服务器端meteor this.userprofile
我有以下代码在集合中呈现currentUsers的文档。但是,我希望属于同一组织的管理员也能够查看和编辑集合。很遗憾,此.user.profile.organization无法工作。那么,我如何允许属于同一组织的管理员使用该对象呢。创建的每个文档都会获得当前用户的组织服务器端meteor this.userprofile,meteor,admin,document,Meteor,Admin,Document,我有以下代码在集合中呈现currentUsers的文档。但是,我希望属于同一组织的管理员也能够查看和编辑集合。很遗憾,此.user.profile.organization无法工作。那么,我如何允许属于同一组织的管理员使用该对象呢。创建的每个文档都会获得当前用户的组织 Meteor.publish('skills', function skillsPublication() { return Skills.find({ owner: this.userId, });
Meteor.publish('skills', function skillsPublication() {
return Skills.find({
owner: this.userId,
});
});
在服务器上时,始终可以从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
})
})
请注意,Meteor建议不要在用户集合中使用.profile
字段,因为该字段总是发布到客户端。Meteor建议您在用户文档上使用顶级键
有关更多信息,请阅读: