db.A1.aggregate([{$match:{B.X: {$in:A2}}}, {$group:{_id:"$ID",Sum: { $sum:"$B.X"}}}, {$sort:{Sum: 1}} ])
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)