Skip to content

Instantly share code, notes, and snippets.

@lionants02
Created November 20, 2019 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lionants02/36e92c0f4478d838975938fa9c0d673a to your computer and use it in GitHub Desktop.
Save lionants02/36e92c0f4478d838975938fa9c0d673a to your computer and use it in GitHub Desktop.
const query = [
{
"$match": {
"$and": [
{
"death.date": {
"$exists": false
}
}
]
}
},
{
"$project": {
"age": {"$subtract": [{"$year": new Date()}, {"$year": "$birthDateMongo"}]},
"sex": 1
}
},
{
"$group": {
"_id": {"age": "$age", "sex": "$sex"},
"count": {"$sum": 1}
}
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment