繁体   English   中英

通过Meteor中的用户个人资料更新元素

[英]Update element from user profile in Meteor

我正在尝试使用onCreateUser更新在user.profile创建的firstName字段:

Accounts.onCreateUser(function(options, user) {
    user.profile = options.profile || {};
    user.profile.firstName = options.firstName;
    return user;
});

我也使用allow:

Meteor.users.allow({
    update: function(userId, doc, fields, modifier) {
        if (fields === "profile.firstName") {
            return true;
        }
    }
});

当我使用时:

Meteor.users.update({
    _id: Meteor.userId()
}, {
    $set: {
        profile: "George"
    }
});

它有效,但这不是我需要的。

我需要更新firstName

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

但是我得到这个错误:

SyntaxError:缺少:属性ID之后

我想念什么?

如果使用的是点符号 ,则需要将整个虚线字段名称括在引号中。

在您的情况下:

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

阅读有关更新嵌入式字段的更多信息。

暂无
暂无

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

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