如何在Chrome控制台中更新Meteor用户? 这不会删除安装中包含的任何不安全和自动发布。
这是我在Chrome控制台中输入的内容:
Meteor.users.update({_ id:' ARfiiEDnk6NbCEzcX'},{$ set:{displayName:' test'}})
这就是我得到的:
1
debug.js:41更新失败:访问被拒绝
答案 0 :(得分:1)
您无法更新Meteor.users
集合,因为出于安全原因,默认情况下禁用此集合上的写入,无论是否存在insecure
包。但是 - 这个规则有两个例外:
{ $set: { 'profile.username': '' } }
如果您真的想要更新用户文档的不同字段,那么您至少有两种可能的选择:
Meteor.users.allow
规则look here 我会推荐第一种解决方案,因为它更安全。
还有一件事。默认情况下,服务器仅publishes来自Meteor.users
集合的一些字段,包括emails
和profile
。如果您计划拥有更多这些内容并且希望它们在浏览器中可用,则需要添加自定义发布功能,例如
Meteor.publish('myCustomField', function () {
return Meteor.users.find({ _id: this.userId },
{ fields: { myCustomField: 1 } });
});
然后在客户端订阅:
Meteor.subscribe('myCustomField');