如何检索Meteor用户配置文件属性的值?

时间:2016-12-02 04:04:49

标签: mongodb meteor

我的Meteor.users.profile中有以下属性。

"profile" : {
        "annualLeave" : 14,
        "replancementLeace" : 0,
        "medicalLeace" : 7
    }

我想玩annualLeave值。

如何在另一个变量中检索annualLeave的值?

2 个答案:

答案 0 :(得分:0)

创建像以下一样的流星调用:

我建议使用ID而不是用户名。

Meteor.call('getUser','username',(error)=>{ //client
    if(error){
      console.log(error.reason)
  }

})

在服务器端:

Meteor.methods({
    getUser(username){
       Meteor.users.findOne({'username':username}).profile.annualLeave // no recommended
             OR
       Meteor.users.findOne({_id:id})// supply id instead of username
  }
})

答案 1 :(得分:0)

这应该有效

var annualL = Meteor.users.find({'username':'your user name'}).fetch()
 console.log(annualL[0].profile.annualLeave);
相关问题