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 value, but not work. I tried this:
Collection.update({createdBy: user_id}, {$inc: { items.$.nameItem: valueOne}} );
Collection.update({createdBy: user_id}, {$inc: { "items.$.nameItem": valueOne}} );
Collection.update({createdBy: user_id}, {$inc: { "items."+nameItem: valueOne}} );
Collection.update({createdBy: user_id}, {$inc: { "items."+nameItem: 1}} );
var object = { $inc: { "items."+nameItem: valueOne} };
Collection.update({createdBy: user_id}, object );
var object = { $inc: { items.$.nameItem: valueOne} };
Collection.update({createdBy: user_id}, object );
But none works and I get this message:
"errorClass {error: 409, reason: "MinimongoError: Cannot apply $inc modifier to non-number", details: undefined, message: "MinimongoError: Cannot apply $inc modifier to non-number [409]", errorType: "Meteor.Error"}"
It's a issue o incompatibility?