从客户端更新Meteor.users [英] Updating Meteor.users from client

查看:90
本文介绍了从客户端更新Meteor.users的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单试图使用以下助手更新meteor.users以及有关用户的额外信息

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

另一个问题是,我想知道是否应该直接向Meteor.users集合进行额外更新,或者我应该有一个单独的集合来存储这些数据。

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 的Meteor文档:

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.

这意味着您可以更新任何这些用户属性,但如果要添加其他属性,最好将它们添加到其中一个已存在的字段中。我建议在profile属性中添加类似`firstName'的东西。在这种情况下,您的代码看起来像这样:

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}});

这篇关于从客户端更新Meteor.users的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆