So, I am thinking of implementing a games property like this,
{
games: {
won: 2,
lost: 3,
played: 5,
winRatio: 40
}
}
I want to modify game ratio each time I add a games win / lose data. For example if in above example if the player wins another game, then the operations would be ,
- increment won by 1
- increment played by 1
- winRatio = 100 * won / played
So, { $inc: { won: 1, played 1 } } and some other stuff.
So, how do I do it? One obvious answer is fetch data, doing calculation and sending data. But I don’t want to do it. I want to do this by the MongoDB methods and operators. Is it possible?