簡體   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