I am getting below documents after my $project , but now I need to find out the average of the transactions. Below are the documents after my '$project', before '$group'
{ "name" : "AAA", "transactions" : [ { "amount" : 500000 }, { "amount" : 12700000 }, { "amount" : 27500000 } ] } { "name" : "BBBB", "transactions" : [ { "amount" : 2500000 }, { "amount" : 5500000 }, { "amount" : 18000000 } ] } { "name" : "CCCC", "transactions" : [ { "amount" : 10000000 }, { "amount" : 5000000 }, { "amount" : 1000000 } ] } I tried something like this.
{$group:{"_id":"$name", average:{$avg:"$transactions.amount"}}} I am printing name values in _id field but the 'average' is printing 'null'
here is the output I am getting
{ "_id" : "AAA", "average" : null } { "_id" : "BBB", "average" : null } { "_id" : "CCC", "average" : null } what am I missing?