I'm new to this topic of aggregations
. I have in my database a structure like this:
{
"world": "Comic",
"characters": [
{
"character": "megaman",
"type":"hero",
"code":"123"
},
{
"character": "dr willow",
"type":"villain",
"code":"1234"
},
{
"character": "spiderman",
"type":"hero",
"code":"12345"
},
{
"character": "venom",
"type":"villain",
"code":"123456"
}
]
}
I would like to output that if the character
is of type
= heroe
it is added to the array of array_heroe
and if it is a villain
it is added to the array of array_villain
.
how can I do it?
I would expect this output for this case:
{
"array_hero": [
{
"character": "megaman",
"type": "hero",
"code": "123"
},
{
"character": "spiderman",
"type": "hero",
"code": "12345"
}
],
"array_villain": [
{
"character": "dr willow",
"type": "villain",
"code": "1234"
},
{
"character": "venom",
"type": "villain",
"code": "123456"
}
]
}