Database

[{"id":"1","emp_name":"emp1","data":[{"emp_country":"country1","emp_city":"city1","salary":[{"currency":"INR","amount":5000},{"currency":"INR","amount":600},{"currency":"MXN","amount":400}]},{"emp_country":"country1","emp_city":"city2","salary":[{"currency":"DOLLER","amount":5000},{"currency":"DOLLER","amount":200},{"currency":"MXN","amount":400}]}]},{"id":"2","emp_name":"emp2","data":[{"emp_country":"country2","emp_city":"city2","salary":[{"currency":"INR","amount":5000},{"currency":"MXN","amount":200},{"currency":"MXN","amount":400}]}]},{"id":"3","emp_name":"emp3","data":[{"emp_country":"country1","emp_city":"city1","salary":[{"currency":"MXN","amount":400}]}]},{"id":"4","emp_name":"emp4","data":[{"emp_country":"country1","emp_city":"city2","salary":[{"currency":"DOLLER","amount":200}]}]}]

Query

db.collection.aggregate([{"$unwind":{"path":"$data"}},{"$unwind":{"path":"$data.salary"}},{"$group":{"_id":{"emp_city":"$data.emp_city","emp_country":"$data.emp_country","emp_name":"$emp_name","currency":"$data.salary.currency",},"max":{"$max":"$data.salary.amount"},"min":{"$min":"$data.salary.amount"}}},{"$group":{"_id":{"emp_city":"$_id.emp_city","emp_country":"$_id.emp_country","emp_name":"$_id.emp_name",},"emp_salary":{"$push":{"currency":"$_id.currency","min":"$min","max":"$max"}}}},{"$project":{"_id":0,"emp_city":"$_id.emp_city","emp_country":"$_id.emp_country","emp_name":"$_id.emp_name","emp_salary":1,}}])

Result