In this code, which uses the mongodb native driver, I would like to increase the value of the field, which I will specify in a separate variable. The problem is that the field name in the $ inc clause will be "variable" in this case, not the contents of the variable. In the query part, the selected variable works as expected and finds the correct identifier.
var selected = 'id_of_the_selected_one'; var variable = 'some_string'; collection.findAndModify( {_id : selected}, {}, {$inc : {variable : 1}}, {new : true, upsert : true}, function(err, autoincrement) { } );
How can I do this so that instead of the word "variable" is the contents of the variable?
source share