Database
[{"productId":"xxx","date":"2018-09-13","prices":[{"country":"en","price":116.5,"currency":"EUR"},{"country":"es","price":17.78,"currency":"EUR"},{"country":"fr","price":18.08,"currency":"EUR"},{"country":"de","price":18.89,"currency":"EUR"},{"country":"it","price":27.49,"currency":"EUR"}]},{"productId":"xxy","date":"2018-09-13","prices":[{"country":"en","price":16.5,"currency":"EUR"},{"country":"es","price":17.78,"currency":"EUR"},{"country":"fr","price":18.08,"currency":"EUR"},{"country":"de","price":12312.89,"currency":"EUR"},{"country":"it","price":997.49,"currency":"EUR"}]}]
Query
db.collection.aggregate([{"$match":{"date":"2018-09-13"}},{"$group":{"_id":"$productId","prices":{"$last":"$prices"}}},{"$addFields":{"pricesObj":{"$map":{"input":"$prices","in":{"k":"$$this.country","v":"$$this.price"}}}}},{"$addFields":{"pricesObj":{"$arrayToObject":"$pricesObj"}}},{"$addFields":{"reference":"$pricesObj.es"}},{"$addFields":{"differences":{"$map":{"input":"$prices","in":{"country":"$$this.country","difference":{"$abs":{"$subtract":["$$this.price","$reference"]}}}}}}},{"$addFields":{"biggestDifference":{"$reduce":{"input":"$differences","initialValue":{difference:0},"in":{"$cond":[{"$gt":["$$this.difference","$$value.difference"]},"$$this","$$value"]}}}}},{"$project":{"_id":1,"biggestDifference":"$biggestDifference.difference"}},{"$sort":{"biggestDifference":-1}}])