如何在控制台中更新Meteor的用户

时间:2015-03-12 19:32:28

标签: meteor meteor-accounts

如何在Chrome控制台中更新Meteor用户? 这不会删除安装中包含的任何不安全和自动发布。

这是我在Chrome控制台中输入的内容:

  

Meteor.users.update({_ id:' ARfiiEDnk6NbCEzcX'},{$ set:{displayName:' test'}})

这就是我得到的:

  

1

     

debug.js:41更新失败:访问被拒绝

1 个答案:

答案 0 :(得分:1)

您无法更新Meteor.users集合,因为出于安全原因,默认情况下禁用此集合上的写入,无论是否存在insecure包。但是 - 这个规则有两个例外:

  1. 客户可以创建新的用户帐户。
  2. 登录的用户可以更新其个人资料,例如: { $set: { 'profile.username': '' } }
  3. 如果您真的想要更新用户文档的不同字段,那么您至少有两种可能的选择:

    1. 在您的服务器上创建自定义方法 - 始终允许在服务器上写入
    2. 添加其他Meteor.users.allow规则look here
    3. 我会推荐第一种解决方案,因为它更安全。

      还有一件事。默认情况下,服务器仅publishes来自Meteor.users集合的一些字段,包括emailsprofile。如果您计划拥有更多这些内容并且希望它们在浏览器中可用,则需要添加自定义发布功能,例如

      Meteor.publish('myCustomField', function () {
        return Meteor.users.find({ _id: this.userId },
            { fields: { myCustomField: 1 } });
      });
      

      然后在客户端订阅:

      Meteor.subscribe('myCustomField');