Database
[{"_id":{"$oid":"6447544a4e512379dee1ced4"},"name":"Mike Trout","uniformNumber":27,"team":"Los Angeles Angels","date":"2023/02","totalHomeruns":333},{"_id":{"$oid":"644755b54e512379dee1ced5"},"name":"Shohei Ohtani","uniformNumber":17,"team":"Los Angeles Angels","date":"2023/03","totalHomeruns":337},{"_id":{"$oid":"644755b54e512379dee1ced6"},"name":"Aaron Judge","uniformNumber":99,"team":"New York Yankees","date":"2023/01","totalHomeruns":295},{"_id":{"$oid":"644755b54e512379dee1ced7"},"name":"Mookie Betts","uniformNumber":11,"team":"Los Angeles Dodgers","date":"2023/01","totalHomeruns":251},{"_id":{"$oid":"644755b54e512379dee1ced8"},"name":"Bryce Harper","uniformNumber":25,"team":"Philadelphia Phillies","date":"2023/02","totalHomeruns":217},{"_id":{"$oid":"644755b54e512379dee1ced9"},"name":"Ronald Acuna Jr.","uniformNumber":23,"team":"Atlanta Braves","date":"2023/02","totalHomeruns":229},{"_id":{"$oid":"644755b54e512379dee1cee1"},"name":"Marcus Semien","uniformNumber":19,"team":"Texas Rangers","date":"2023/03","totalHomeruns":196},{"_id":{"$oid":"644755b54e512379dee1cee2"},"name":"Vladimir Guerrero Jr.","uniformNumber":6,"team":"Toronto Blue Jays","date":"2023/03","totalHomeruns":188},{"_id":{"$oid":"644755b54e512379dee1cee3"},"name":"Yordan Alvarez","uniformNumber":10,"team":"Houston Astros","date":"2023/02","totalHomeruns":137},{"_id":{"$oid":"644755b54e512379dee1cee4"},"name":"Andrew Benintendi","uniformNumber":23,"team":"Chicago Whitesox","date":"2023/02","totalHomeruns":116},{"_id":{"$oid":"644755b54e512379dee1cee5"},"name":"Wander Franco","uniformNumber":33,"team":"Tampa Bay Rays","date":"2023/02","totalHomeruns":97}]
Query
db.collection.aggregate([{"$group":{"_id":{$concat:[{$cond:{if:{$lt:["$totalHomeruns",95]},then:"0",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",95]},{$lt:["$totalHomeruns",105]}]},then:"95",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",105]},{$lt:["$totalHomeruns",115]}]},then:"105",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",115]},{$lt:["$totalHomeruns",125]}]},then:"115",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",125]},{$lt:["$totalHomeruns",135]}]},then:"125",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",135]},{$lt:["$totalHomeruns",145]}]},then:"135",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",145]},{$lt:["$totalHomeruns",155]}]},then:"145",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",155]},{$lt:["$totalHomeruns",165]}]},then:"155",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",165]},{$lt:["$totalHomeruns",175]}]},then:"165",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",175]},{$lt:["$totalHomeruns",185]}]},then:"175",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",185]},{$lt:["$totalHomeruns",195]}]},then:"185",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",195]},{$lt:["$totalHomeruns",205]}]},then:"195",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",205]},{$lt:["$totalHomeruns",215]}]},then:"205",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",215]},{$lt:["$totalHomeruns",225]}]},then:"215",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",225]},{$lt:["$totalHomeruns",235]}]},then:"225",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",235]},{$lt:["$totalHomeruns",245]}]},then:"235",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",245]},{$lt:["$totalHomeruns",255]}]},then:"245",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",255]},{$lt:["$totalHomeruns",265]}]},then:"255",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",265]},{$lt:["$totalHomeruns",275]}]},then:"265",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",275]},{$lt:["$totalHomeruns",285]}]},then:"275",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",285]},{$lt:["$totalHomeruns",295]}]},then:"285",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",295]},{$lt:["$totalHomeruns",305]}]},then:"295",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",305]},{$lt:["$totalHomeruns",315]}]},then:"305",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",315]},{$lt:["$totalHomeruns",325]}]},then:"315",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",325]},{$lt:["$totalHomeruns",335]}]},then:"325",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",335]},{$lt:["$totalHomeruns",345]}]},then:"335",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",345]},{$lt:["$totalHomeruns",355]}]},then:"345",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",355]},{$lt:["$totalHomeruns",365]}]},then:"355",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",365]},{$lt:["$totalHomeruns",375]}]},then:"365",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",375]},{$lt:["$totalHomeruns",385]}]},then:"375",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",385]},{$lt:["$totalHomeruns",395]}]},then:"385",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",395]},{$lt:["$totalHomeruns",405]}]},then:"395",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",405]},{$lt:["$totalHomeruns",415]}]},then:"405",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",415]},{$lt:["$totalHomeruns",425]}]},then:"415",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",425]},{$lt:["$totalHomeruns",435]}]},then:"425",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",435]},{$lt:["$totalHomeruns",445]}]},then:"435",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",445]},{$lt:["$totalHomeruns",455]}]},then:"445",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",455]},{$lt:["$totalHomeruns",465]}]},then:"455",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",465]},{$lt:["$totalHomeruns",475]}]},then:"465",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",475]},{$lt:["$totalHomeruns",485]}]},then:"475",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",485]},{$lt:["$totalHomeruns",495]}]},then:"485",else:""}},{$cond:{if:{$and:[{$gte:["$totalHomeruns",495]},{$lt:["$totalHomeruns",505]}]},then:"495",else:""}},/** To-do: handle 'Infinity'*/{$cond:{if:{$gt:["$totalHomeruns",505]},then:"515",else:""}}]},count:{$sum:1},playerData:{$push:{name:"$name",uniformNumber:"$uniformNumber",team:"$team",totalHomeruns:"$totalHomeruns",date:"$date"}}}},{"$sort":{_id:1}}])