I have this mongo collection and vars:
items:{ type_one: 0, type_two: 0 } var valueOne = 1; var nameItem = type_one;
I try to update a
You need to build your query dynamically using the bracket [] operator. Also "nameItem" must be a string.
[]
var valueOne = 1; var nameItem = 'type_one'; var inc = {}; inc[ 'items.' + nameItem ] = valueOne; Collection.update({ createdBy: user_id }, { '$inc': inc } )