Reputation: 3184
Like the questions asks, can this be done?
I would like to insert an array of a user's links into the current user's profile. I tried something like following on the client side but it did not work:
Meteor.users.update( {_id: Meteor.userId()}, {
$set: {
profile: {
userlinks: {
owned: "_entry_id"
}
}
}
});
I also tried replacing update with insert but to not avail.
I have a couple of suspicions about what it could be:
Or maybe I just have no idea what I am talking about (most likely)
Upvotes: 0
Views: 1261
Reputation: 86
Check Meteor Update Docs your syntax is wrong. Try:
var id = Meteor.userId();
Meteor.users.update( id, {
$set: {
profile: {
userlinks: {
owned: "_entry_id"
}
}
}
});
Upvotes: 3
Reputation: 56
You can do that, your user needs to have a profile field to start with if you're using a custom account UI make sure you set the profile to something when you authenticate a user even if it's just a blank object to start with:
var options = {
username: 'some_user',
password: 'password',
email: '[email protected]',
profile: {}
}
Accounts.createUser(options, function(err){
if(err){
//do error handling
}
else
//success
});
if you've removed the insecure package you'll need to make sure you setup the Meteor.users.allow
something like:
Meteor.users.allow({
update: function(userId, doc, fieldNames, modifier){
if(userId === doc._id && fieldNames.count === 1 && fieldNames[0] === 'profile')
return true;
}
})
so that the user can only update themselves and they can only update the profile field.
Upvotes: 1