In MongoDB, is it possible to update the value of a field using the value from another field?
sample doc in DB:
{
"_id" : 1,
"total":0,
"amount1":100
}
i wanted to update "total" = "amount1"+250;
expected result in DB:
{
"_id" : 1,
"total":350,
"amount1":100
}
i tried with below query, but not worked.
db.getCollection('test').update({"_id" : 1)},
{"$set":{"total":{ "$sum": { 250: "$amount1"}}}});
Please help me to solve this.