db.getCollection('tmp').aggregate( [
// First Stage
{
$unwind: { path: "$faceAmtMap", preserveNullAndEmptyArrays: true }
},
// Second Stage
{
$group:
{
_id: "$faceAmtMap.age",
averagePrice: { $max: "$faceAmtMap.faceAmt" }
}
},
// Third Stage
{
$sort: { "averagePrice": -1 }
}
] )