我有一个表单尝试使用以下帮助程序更新meteor.users,其中包含有关用户的额外信息
Template.Profile.events({
'submit form': function(e) {
e.preventDefault();
var post = {
firstName: $(e.target).find('[name=firstname]').val()
};
Meteor.users.update( { _id: Meteor.userId() }, { $set: { 'firstName': post.firstName }} );
}
});
但是,我更新失败:访问被拒绝
另一个问题是,我想知道是否应该直接对 Meteor.users 集合进行额外更新,或者应该有一个单独的集合来存储这些数据。
谢谢
最佳答案
由于您尝试直接在基本用户对象上设置属性,因此您收到“访问被拒绝”错误。根据 Meteor 文档 Meteor.users :
By default, the current user's
username
,emails
, andprofile
are published to the client.
这意味着您可以更新任何这些用户属性,但如果您想添加其他用户属性,最好将它们添加到这些已存在的字段之一。我建议在个人资料属性中添加诸如“firstName”之类的内容。在这种情况下,您的代码将如下所示:
Meteor.users.update({_id: Meteor.userId()}, {$set: {'profile.firstName': post.firstName}});
关于javascript - 从客户端更新 Meteor.users,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29407881/