I have a set of files in the following format:
{
"user": { "username": "string" }
"points": 123
}
My goal is to determine a user's position within the set.
collection.aggregate([
{ $sort: { points: -1 } }, // arrange by points descending
{
$project: {
points: '$points'
position: {
$indexOfArray: [
'$', // I'm unsure what value should go here
{ 'user.username': 'myUser' }
]
}
}
}
]);
How can I handle the set as an array?
The desired output is:
[
{
"points": 123,
"position": 1
}
]