[英]Meteor Collection empty on server
我得到了一個名為Admins的集合,並使用Admins.findOne({userId: Meteor.userID})
來檢查用戶是否是管理員,並且在流星外殼中使用它並調用它時,是否可以正常運行?我已經從瀏覽器控制台為它定義了一個方法,但是當我使用它進行服務器端權限檢查時,Admins集合似乎為空( Admins._collection._docs._map
為空。我已經檢查了。)。 我不知道為什么如果我在服務器端執行它,為什么我的方法不能訪問它,但是當我從chrome開發工具中調用它時,它可以很好地工作。 我的方法是:
updateArticle: (id, obj) ->
console.log Admins //appears to be empty
console.log Meteor.userId()
Meteor.call 'hasBasicPermissions', (err,res) ->
console.log res // false
if res
Articles.update(id, obj)
else
Meteor.call('notAuthorisedError') // throws the error
isEditor: ->
!!Editors.findOne {userId: Meteor.userId()} // return true when called in Meteor shell, but is false when used in the method, but only on the server side
isAdmin: ->
!!Admins.findOne {userId: Meteor.userId()}
hasBasicPermissions: ->
console.log(Meteor.userId())
console.log(Admins)
res = !!Admins.findOne({userId: "9fZmAnoJubaGDZH64"}) or !!Admins.findOne({userId: "9fZmAnoJubaGDZH64"})
console.log res
return res
notAuthorisedError : ->
throw new Meteor.Error("not-authorized");
我猜想您是在僅在客戶端上執行代碼的位置( client
文件夾中的文件中@Admins = new Meteor.Collection('admins')
定義集合( @Admins = new Meteor.Collection('admins')
或類似的行)。在Meteor.isClient
塊中。 嘗試將其放在共享代碼中,例如在lib
或collections
文件夾中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.