$rank/$denseRank/$documentNumber
Reference group: Accumulators and ranking
What it does
Computes ranks or row numbers in a window context.
Syntax
Window output expressions
Use case
Leaderboards and ordered reports.
$rank/$denseRank/$documentNumber: practical example
{ $setWindowFields: { sortBy: { score: -1 }, output: { rank: { $rank: {} }, row: { $documentNumber: {} } } } }💡 Explanation
Computes ranks or row numbers in a window context.
When to use it
Leaderboards and ordered reports.
Key Takeaways
- Computes ranks or row numbers in a window context.
- Typical use: Leaderboards and ordered reports.