I have datas in my mongoDB as follow
{
"stack":"webTechnology",
"subStack":"angular"
},
{
"stack":"webTechnology",
"subStack":"react"
}.
{
"stack":"webTechnology",
"subStack":"angular"
},
{
"stack":"script",
"subStack":"python"
},
{
"stack":"script",
"subStack":"javaScript"
},
{
"stack":"Java",
"subStack":"Spring"
}
I need to return these data as response from Rest API in the following format, Categorized by stack and substack
[
"webTechnology":[
"angular":[
{
"stack":"webTechnology",
"subStack":"angular"
},
{
"stack":"webTechnology",
"subStack":"angular"
}
],
"react":[
{
"stack":"webTechnology",
"subStack":"react"
}
]
],
"script":[
"python":[
{
"stack":"script",
"subStack":"python"
}
],
"javaScript":[
{
"stack":"script",
"subStack":"javaScript"
}
]
],
"java":[
"spring":[
{
"stack":"java",
"subStack":"spring"
}
]
]
]
Im using mongoTemplate to retrieve the data, which is returning in the List format
mongoTemplate.getCollection(collectionName).find().toArray()
How can I get the result in the way which Im expecting?