Database

[{"collection":"productos","database":"test","count":2,"content":{"_id":{"type":"ref","id":1,"refContent":{"type":"objectId"}},"nombre":{"type":"fromArray","in":["prestamo joven","prestamo adulto"]},"montoMaximo":{"type":"int","minInt":300000,"maxInt":300000},"edadMinMax":{"type":"fromArray","in":[30,31]}}},{"collection":"solicitudes","database":"test","count":100,"content":{"nombreCompleto":{"type":"faker","method":"Name"},"fechaSolicitud":{"type":"date","startDate":"2019-01-01T00:00:00+00:00","endDate":"2020-12-31T23:59:59+00:00"},"productoSolicitado":{"type":"ref","id":1},"edad":{"type":"int","minInt":18,"maxInt":50},"montoSolicitado":{"type":"int","minInt":10000,"maxInt":1000000}}}]

Query

db.solicitudes.aggregate([{"$lookup":{"from":"productos","localField":"productoSolicitado","foreignField":"_id","as":"productos"}},{"$match":{"edad":{"$lte":30},"montoSolicitado":{"$lte":300000},"productos.nombre":"prestamo joven"}},{"$unwind":"$productos"},{"$group":{"_id":"$productoSolicitado","nombreProducto":{"$last":"$productos.nombre"},"promedioEdad":{"$avg":"$edad"},"cantidadSolicitudes":{"$sum":1}}},])

Result