I need to update a field using some expression. Given a DBObject query, how can I multiply or divide given field by an argument value?
How can I write a function performing operation something like this, but in Java:
function(DBObject queryObject, String fieldToUpdate, Double argumentValue) {
collection.find(queryObject).forEach(function(e) {
// update field given by input argument "fieldToUpdate", something like..
// e.put(fieldToUpdate, e.get(fieldToUpdate)/argumentValue); ??
collection.save(e);
});
}
Is it possible using "$set" and find() or findAndModify()? If yes, how can update existing value using an expression like existingValue / argumentValue?