My mongo data are in the following format:
{ country: "Bangladesh", city: "Dhaka", name: "Jobayer", email: "[email protected]" }
{ country: "Bangladesh", city: "Dhaka", name: "Mehotaz", email: "[email protected]" }
{ country: "KSA", city: "Dammam", name: "Jabal", email: "[email protected]" }
I want to retrieve data like below:
[
{
country: 'Bangladesh',
cities: [
{
city: 'Dhaka',
contacts: [
{
name: 'Jobayer',
email: '[email protected]'
},
{
name: 'Mehotaz',
email: '[email protected]'
}
]
}
]
},
{
country: 'KSA',
cities: [
{
city: 'Dammam',
contacts: [
{
name: 'Jabal',
email: '[email protected]'
}
]
}
]
}
];
I have tried some group operations but could not get the expected result. Please provide your valuable suggestion on how can I achieve that.