I know how to update objects within an array like the following:
db.bar.update( {user_id : 123456 , "items.item_name" : "my_item_two" } ,
{$inc : {"items.$.price" : 1} } ,
false ,
true);
But, im trying to currently update a object.
model:
boats: {
cash: {type: Number, default: 0},
amount: { type: Number, default: 0}
},
murder: {
attempts: {type: Number, default:0},
failed_attempts: {type: Number, default:0},
successfull_attempts: {type: Number, default:0},
cash: {type: Number, default: 0},
amount: { type: Number, default: 0}
},
orgcrime: {
cash: {type: Number, default: 0},
amount: { type: Number, default: 0}
},
i have a variable called type that contains the word i want to update, for example: murder . I also have a variable called num, that will be updated value.
CurrentStats contains the full model result.
i get the types object by doing:currentStats[type]` , but how can i update it?
i tried with:
var x = {};
x[type].cash = num;
x[type].amount = 1;
and {$inc: x} , but that wouldnt work.
How would i go about this?