2017-05-31 181 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