How to fetch the MongoDB collection data unique with two-column emp_country and emp_city and return the array with these two data in the array format.
I need pagination also with country and city. So, when I got unique data, then I can apply pagination as well. Expected output as below mentioned in example and also need for pagination but data should be unique in response.
Sample data:
[
{
"id":"1",
"emp_name":"emp1",
"data":[{
"emp_country":"country1",
"emp_city":"city1"
},
{
"emp_country":"country1",
"emp_city":"city2"
}]
},
{
"id":"2",
"emp_name":"emp2",
"data":[{
"emp_country":"country2",
"emp_city":"city2"
}]
},
{
"id":"3",
"emp_name":"emp3",
"data":[{
"emp_country":"country1",
"emp_city":"city1"
}]
},
{
"id":"4",
"emp_name":"emp4",
"data":[{
"emp_country":"country1",
"emp_city":"city2"
}]
}
]
Expected output:
[
{
"emp_country":"country1",
"emp_city":"city1"
},
{
"emp_country":"country2",
"emp_city":"city2"
},
{
"emp_country":"country1",
"emp_city":"city2"
}
]
How to achieve the above result using Java and MongoDB?