服务器端流星 this.userprofile
Server side meteor this.userprofile
我有以下代码在集合中呈现 currentUsers 的文档。但是,我希望属于同一组织的管理员也能够查看和编辑该集合。不幸的是,this.user.profile.organization 不起作用。那么,我将如何允许属于同一组织的管理员使用该对象。创建的每个文档都会获取当前用户的组织。
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 建议您改用用户文档中的顶级键。
有关详细信息,请阅读:https://guide.meteor.com/accounts.html#dont-use-profile
我有以下代码在集合中呈现 currentUsers 的文档。但是,我希望属于同一组织的管理员也能够查看和编辑该集合。不幸的是,this.user.profile.organization 不起作用。那么,我将如何允许属于同一组织的管理员使用该对象。创建的每个文档都会获取当前用户的组织。
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 建议您改用用户文档中的顶级键。
有关详细信息,请阅读:https://guide.meteor.com/accounts.html#dont-use-profile