I am trying to update firstName
field created in user.profile
using onCreateUser
:
Accounts.onCreateUser(function(options, user) {
user.profile = options.profile || {};
user.profile.firstName = options.firstName;
return user;
});
Also I use allow:
Meteor.users.allow({
update: function(userId, doc, fields, modifier) {
if (fields === "profile.firstName") {
return true;
}
}
});
When I use:
Meteor.users.update({
_id: Meteor.userId()
}, {
$set: {
profile: "George"
}
});
It works but it is not what I need.
What I need is to update firstName
:
Meteor.users.update({
_id: Meteor.userId()
}, {
$set: {
profile.firstName: "George"
}
});
But I get this error:
SyntaxError: missing : after property id
What am I missing?
If you are using the dot notation you need to enclose the whole dotted field name in quotes.
In your case:
Meteor.users.update({
_id: Meteor.userId()
}, {
$set: {
"profile.firstName": "George"
}
});
Read more about updating an embedded field .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.