Javascript Accounts.onCreateUser未将字段添加到Meteor';s用户集合

Javascript Accounts.onCreateUser未将字段添加到Meteor';s用户集合,javascript,meteor,Javascript,Meteor,我想在Meteor的用户集合中添加一个新字段: server/fixtures.js: Accounts.onCreateUser(function(options, user) { user.role = 'Student' // We still want the default hook's 'profile' behavior. if (options.profile) user.profile = options.profile; return user })

我想在Meteor的用户集合中添加一个新字段:

server/fixtures.js:

Accounts.onCreateUser(function(options, user) {
  user.role = 'Student'
  // We still want the default hook's 'profile' behavior.
  if (options.profile)
    user.profile = options.profile;
  return user
})
  users: function() {
    var users = _.map(Meteor.presences.find().fetch(), function(user) { 
      return Meteor.users.findOne({_id: user.userId})
    })

    return users
  },
但是当我执行
Meteor.users.find().fetch()时

我看不到那块地

在模板中也不起作用:

documents/document\u page.js:

Accounts.onCreateUser(function(options, user) {
  user.role = 'Student'
  // We still want the default hook's 'profile' behavior.
  if (options.profile)
    user.profile = options.profile;
  return user
})
  users: function() {
    var users = _.map(Meteor.presences.find().fetch(), function(user) { 
      return Meteor.users.findOne({_id: user.userId})
    })

    return users
  },
文档/user.html

<template name="user">
  <li class="clearfix">
    <img src="/avatar.png"/>
    <div class="user-info">
      <p>{{userId}}</p>
      <p>{{username}}</p>
      <p>{{role}}</p>
    </div>
  </li>
</template>

  • {{userId}}

    {{username}}

    {{role}}


  • 只显示用户名。可能是什么问题?

    您需要发布自定义字段。从文档中:

    默认情况下,服务器发布用户名、电子邮件和配置文件(可由用户写入)。有关用户文档中使用的字段的更多信息,请参见Meteor.users

    最简单的方法是使用
    null
    名称发布,该名称将自动发布文档,而无需相应的
    Meteor。订阅

    Meteor.publish(null, function() {
      return Meteor.users.find(this.userId, {fields: {role: 1}});
    });
    

    在本例中,我们将发布
    角色
    字段,该字段将与当前用户已发布的默认字段合并。

    您使用的是alining roles包吗?@Ethaan否,我只是制作了一个自定义的。我建议您使用,包,您可以使用html标记,如
    {if isInRole'Admin}在html上访问此内容{/if}
    /
    {{if isInRole'Super Admin}}}在同一html上访问此不同的html内容{/if}
    ,我有代码示例如果你想知道,我是一个流星新手。我应该把代码放在哪里?现在我仍在使用
    autopublish
    软件包,因此我没有发布我的收藏的位置。
    您已使用Meteor.publish()设置了一些数据订阅,但I20150128-12:27:57.115(8)?**您仍然打开了“自动发布”。因为autopublish仍然是
    ,我想只有当我删除
    autopublish
    包时我才能这样做。@David Weldon有一个问题:如果我把代码放在我的
    /server/
    文件夹中的一个新文件中,那么
    this.userId
    指向什么?@alexchenco(1)如果您愿意,您可以忽略警告并保持autopublish打开-您仍然需要此发布来获取用户字段。(2) 将发布放在
    server
    目录下的任何文件中,例如
    server/publisher.js
    。(3)
    this.userId
    将是连接用户的id-它自动可用于发布功能,用户登录后,您的发布将自动触发。