Here is my data in mongodb
{
"_id" : ObjectId("5a77e82c19e5b90363fe55d4"),
"serviceId" : 85,
"clusterId" : 122,
"metricTimestamp" : ISODate("2018-02-05T04:33:58.000Z"),
"metricNames" : [
"host",
"count",
"time",
"out"
],
"metricValues" : [
"wwe.123.com",
"8829",
"2018-02-05T04:16:02.685Z",
"25327782"
],
"createtime" : ISODate("2018-02-05T05:14:20.273Z")
}
and I want to aggregate the data:
db.getCollection('metrics.value').aggregate([
{ $match: {
'serviceId': 85,
'metricTimestamp':{
$gte: ISODate("2018-02-03T04:33:58"),
$lte: ISODate("2018-02-05T04:33:58")
}
}},
{ $project: {
host: { $arrayElemAt:["$metricValues", 0]},
count:{ $arrayElemAt:["$metricValues", 1]}
},
{$group:{}}
}])
I want to group by host (here it is "wwe.123.com"), and aggregate the count (here it is "8829"). I don't know how to convert from string to int (parseInt is not working). Please help me solve these issues.