Created
June 20, 2022 19:24
-
-
Save paulobunga/85111916cd6b752b1464cb5f2d33a239 to your computer and use it in GitHub Desktop.
Top 10 Staff By Position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const agg = [ | |
{ | |
'$match': { | |
'positionInformation.positionStatus': 'Active' | |
} | |
}, { | |
'$unwind': { | |
'path': '$positionInformation' | |
} | |
}, { | |
'$project': { | |
'_id': 0, | |
'position': '$positionInformation.position', | |
'gender': { | |
'$cond': [ | |
{ | |
'$eq': [ | |
'$gender', '' | |
] | |
}, 'NONE', '$gender' | |
] | |
} | |
} | |
}, { | |
'$group': { | |
'_id': '$position', | |
'male': { | |
'$sum': { | |
'$cond': [ | |
{ | |
'$eq': [ | |
'MALE', '$gender' | |
] | |
}, 1, 0 | |
] | |
} | |
}, | |
'female': { | |
'$sum': { | |
'$cond': [ | |
{ | |
'$eq': [ | |
'FEMALE', '$gender' | |
] | |
}, 1, 0 | |
] | |
} | |
}, | |
'none': { | |
'$sum': { | |
'$cond': [ | |
{ | |
'$eq': [ | |
'NONE', '$gender' | |
] | |
}, 1, 0 | |
] | |
} | |
}, | |
'total': { | |
'$sum': 1 | |
} | |
} | |
}, { | |
'$project': { | |
'_id': 0, | |
'position': '$_id', | |
'total': '$total', | |
'data': { | |
'male': '$male', | |
'female': '$female', | |
'none': '$none' | |
} | |
} | |
}, { | |
'$sort': { | |
'total': -1 | |
} | |
}, { | |
'$limit': 10 | |
} | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment