The following query
db.getCollection("xyzCollection").aggregate(
[
{ $match:
{ "startDate": { $gte: ISODate("2021-01-21T00:00:00.000+0000") } , "markets": { $exists: true }}
},
{ $group:
{ _id: "$sportName" , "count": { $sum: 1 } }
},
]
)
returns the following output:
{
"_id" : "Ice Hockey",
"count" : 138.0
}
{
"_id" : "Basketball",
"count" : 141.0
}
{
"_id" : "Cricket",
"count" : 14.0
}
{
"_id" : "Volleyball",
"count" : 32.0
}
{
"_id" : "Football",
"count" : 685.0
}
Why is this? And how can I make it return an int? I'm using Studio 3T 2020.10.1 to execute the query. I have already tried using $toInt (wrapping the "1" or wrapping the " { $sum: 1 } ") but as expected it didn't work - bad syntax.
Thanks.