I am working on gaming application will have thousands of users.
My current aggregate pipeline output
[
{
"USERID": "U0004",
"Total_Points": 10
},
{
"USERID": "U0001",
"Total_Points": 8
},
{
"USERID": "U0006",
"Total_Points": 8
},
{
"USERID": "U0002",
"Total_Points": 2
},
{
"USERID": "U0003",
"Total_Points": 1
},
{
"USERID": "U0005",
"Total_Points": 1
}
]
Expected Output
[
{
"USERID": "U0004",
"Total_Points": 10,
"Rank": 1
},
{
"USERID": "U0001",
"Total_Points": 8,
"Rank": 2
},
{
"USERID": "U0006",
"Total_Points": 8,
"Rank": 2
},
{
"USERID": "U0002",
"Total_Points": 2,
"Rank": 4
},
{
"USERID": "U0003",
"Total_Points": 1,
"Rank": 5
},
{
"USERID": "U0005",
"Total_Points": 1,
"Rank": 5
}
]
Which is the best and most optimised way to get the output from mongodb aggregate with the leaderboard rank concept.
I am using mongoose mongodb connection in my project.
I can manipulate data using a for loop but it seems rather inefficent.
Thanks in advance.
Comments are greatly appreciated.
Below is image of example leader board