简体   繁体   English

从客户端更新Meteor.users

[英]Updating Meteor.users from client

I have a form that tried to update meteor.users with extra information about users with the following helper 我有一个试图通过以下帮助程序使用有关用户的额外信息来更新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 }} );

  }
});

however, i get update failed: Access denied 但是,我无法更新:访问被拒绝

Another question is, I am wondering whether I should do extra update straight to Meteor.users collection or should I have a seperate collection to store these data. 另一个问题是,我想知道是否应该直接对Meteor.users集合进行额外的更新,还是应该有一个单独的集合来存储这些数据。

thanks 谢谢

Due to the fact that you are trying to set an attribute directly on the base user object, you are receiving the 'Access denied' error. 由于您尝试直接在基本用户对象上设置属性,因此您收到“拒绝访问”错误。 According to the Meteor documentation for Meteor.users : 根据Meteor.users的Meteor文档:

By default, the current user's username , emails , and profile are published to the client. 默认情况下,当前用户的usernameemailsprofile将发布到客户端。

This means that you can update any of those user attributes, but if you want to add additional ones, it is best to add them to one of these already existing fields. 这意味着您可以更新任何这些用户属性,但是如果要添加其他用户属性,则最好将它们添加到这些现有字段之一中。 I would suggest adding something like `firstName' to the profile attribute. 我建议在个人资料属性中添加“ firstName”之类的内容。 In this case, your code would look something like this: 在这种情况下,您的代码将如下所示:

Meteor.users.update({_id: Meteor.userId()}, {$set: {'profile.firstName': post.firstName}});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM