问题描述
以下查询
db.getCollection("xyzCollection").aggregate(
[
{ $match:
{ "startDate": { $gte: ISODate("2021-01-21T00:00:00.000+0000") },"markets": { $exists: true }}
},{ $group:
{ _id: "$sportName","count": { $sum: 1 } }
},]
)
返回以下输出:
{
"_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
}
这是为什么?我怎样才能让它返回一个int?我正在使用 Studio 3T 2020.10.1 来执行查询。我已经尝试过使用 $toInt(包装“1”或包装“{ $sum: 1 }”),但正如预期的那样,它不起作用 - 语法错误。
谢谢。