Is it possible to update a document field based on another field using the update operator?
I have players collection with health and maxHealth, my goal is to reset the player health to the maxHealth value
db={
"players": [
{
"_id": ObjectId("5fba17c1c4566e57fafdcd7e"),
"username": "moshe",
"health": 0,
"maxHealth": 200,
}
]
}
// update
db.players.update({
username: "moshe"
},
{
"$set": {
"health": "$$maxHealth",
}
})
Thanks!