$setWindowFields (aggregation)
Performs operations on a specified span of documents in a collection, known as a , and returns the results based on the chosen window operator. For example, you can use the $setWindowFields stage to output the: Difference in sales between two documents in a collection. Sales rankings. Cumulative sales totals.
https://docs.mongodb.com/manual/reference/operator/aggregation/setWindowFields/?utm_campaign=Int_EM_Tier%20Upgrades%20to%205.0_01_22_WW