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