Javascript 如何在Meteor JS中按ID选择用户?

Javascript 如何在Meteor JS中按ID选择用户?,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,我正在尝试使用MeteorJS显示用户配置文件 每个用户都有一个存储在MongoDB中的配置文件,但在navigator控制台中,它只显示用户名、电子邮件和_id字段 这是我的代码: 在/lib/Router.js中 /server/Publications.js: Meteor.publish("me",function(){ return Meteor.users.find(this.userId,{ fields :{ username : 1, ema

我正在尝试使用MeteorJS显示用户配置文件

每个用户都有一个存储在MongoDB中的配置文件,但在navigator控制台中,它只显示用户名、电子邮件和_id字段

这是我的代码: 在/lib/Router.js中

/server/Publications.js:

Meteor.publish("me",function(){
  return Meteor.users.find(this.userId,{
    fields :{
      username : 1,
      emails : 1,
      profile : 1
    }
  });
});

你的个人资料路线看起来有点古怪。在我看来,您只需要当前用户的配置文件,而不是所有用户。我会这样写:

Router.route('/profile',{
  name : "profile",
  data(){
    return Meteor.user();
  },
  waitOn(){
    return Meteor.subscribe("me");
  }
});
/server/Publications.js:

Meteor.publish("me",function(){
  return Meteor.users.find(this.userId,{
    fields :{
      username : 1,
      emails : 1,
      profile : 1
    }
  });
});

代码在我看来是正确的,相反,你有没有试着为你不需要的字段设置0,而为你需要的字段设置0?另外,我通常在meteor模板中按如下方式执行模板级subcition,而不是路由器级订阅。Template.executiveSingleCode.onCreatedfunction{this.autorun=>{this.subscribe'allUsers'}
Meteor.publish("me",function(){
  return Meteor.users.find(this.userId,{
    fields :{
      username : 1,
      emails : 1,
      profile : 1
    }
  });
});