I have collection of documents in mongodb 2.6.11 where 'cpu' is array showing [cpu0,cpu1], see example below
{ cpu: [ '100','20' ], hostname: 'host1',_id: 1 },
{ cpu: [ '40','30' ], hostname: 'host1',_id: 2 }, etc
I'm looking for average cpu on 'host1' which is ['70','25'] ( because '100'+'40'/2='70' and '20'+'30'='25' ). I am trying aggregate for cpu1 but it is not giving me right result
db.collection.aggregate(
[
{
$group:
{
_id:"hostname",
avgCPU: {$avg: "$cpu.1"}
}
}
]
);