Updating Meteor.users from client

自闭症网瘾萝莉.ら 提交于 2019-12-31 05:49:07

问题


I have a form that tried to update meteor.users with extra information about users with the following helper

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.

thanks


回答1:


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:

By default, the current user's username, emails, and profile are published to the client.

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. In this case, your code would look something like this:

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


来源:https://stackoverflow.com/questions/29407881/updating-meteor-users-from-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!