Reputation: 470
I want to write this call as a Method: Posts.update(this._id, { $set: { status: 'accepted' }})
Meteor.methods({
...
updatePost: function(id, key, value) {
Posts.update(id, { $set: { key: value }});
}
})
Meteor.call('updatePost', this._id, 'status', 'accepted')
does not work. I'm guessing because of the 'status'
? How could I get this to work? Thanks.
Upvotes: 0
Views: 67
Reputation: 75945
Variables can't be defined as keys in javascript. Something like this could do it though:
var update = {};
update[key] = value;
Posts.update(id, { $set: update });
Upvotes: 1
Reputation: 64312
I suspect it isn't working because you can't use variable names as keys in JavaScript object literals. You'll need to use bracket notation instead. Give this a try:
Meteor.methods({
updatePost: function(id, key, value) {
check(id, String);
check(key, String);
check(value, String);
var obj = {};
obj[key] = value;
return Posts.update(id, {$set: obj});
}
});
Upvotes: 2