'node js & mongo db -how to update each document with season rank?

i have an app that runs on node with mongo. the collection (games) has document for each game played with each player's profit from the game('players' is array of 'player' objects). i want to add a field to each player that get the players current season rank (rank is calculated by player.profit value) and his previous season rank (before the last game was played) ..... tried to do it with $setWindowFields but it isnt working...

sample document:

game_id:618a347e720a83570f743f01, isOpen:false, players:Array

0:Object id:"6187a062e29bee6f3a64dfb3", name:"Johnny", profit:600,

1:Object id:"6187a02ae29bee6f3a64dfa8", name:"Janny", profit:50,

2: Object id "6187a0ace29bee6f3a64dfb8" name "the kid" profit -250

games collection img



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source