Reputation: 13587
It is very straightforward implementation but may be there is some problem with my syntax here:
Template.userProfilePage.events({
'submit #profile-page': function(event, template) {
event.preventDefault();
var name = template.find('#fullName').value,
address = template.find('#address').value,
company = template.find('#company').value,
otherField = template.find('#other').value;
alert(name);
Meteor.users.update(
{ _id:Meteor.user()._id },
{
$set: {
"profile.name":name,
"profile.address":address,
"profile.company":company,
"profile.other":other
}
},
{ upsert: true },
{ multi: true }
);
return false;
}
});
Template contains normal html pages. It always throws error:
RangeError: Maximum call stack size exceeded.
Upvotes: 3
Views: 1714
Reputation: 7356
If you’re updating only one user, there’s no need for multi: true
. There should also never be a need to upsert; if you’re working with a logged-in user, there should always be a document for them in the users
collection. Try something like this:
Meteor.users.update(
Meteor.userId(),
{$set: {
"profile.name": name,
"profile.address": address,
"profile.company": company,
"profile.other": other
}
}
);
Also make sure your allow
and deny
rules permit you to do this update.
P.S. I suspect your error message is probably because you have { multi: true }
as the fourth argument to .update
. Per the docs, the syntax is collection.update(selector, modifier, [options], [callback])
; so if you ever want to use both multi
and upsert
, combine them into one object in the third argument: { multi: true, upsert: true }
(you can also just use collection.upsert
instead of .update
). Your error is probably caused by you sending an object, { multi: true }
, as the fourth argument instead of the callback function that update
is expecting.
Upvotes: 2