considering the following document
"logs": {
"events": {
"type": "call_action",
"attributes": [
{
"key": "module",
"value": "module1"
},
{
"key": "data",
"value": "data_value_module_1"
},
{
"key": "module",
"value": "module2"
},
{
"key": "data",
"value": "data_value_module_2"
}
]
}
},
I am trying to use $arraytoObject to convert key and value
$project: {
"attributes": {
$arrayToObject: {
$map: {
"input": "$logs.events.attributes",
"as": "el",
"in": {
"k": "$$el.key",
"v": "$$el"
}
}
}
}
}
but it overwrite duplicated keys as module
and data
.
How can I use a kind of $unwind or something like that?
The result should be like that
[
{
"logs": {
"events": {
"type": "call_action",
"attributes": {
"module": "module1"
"value": "data_value_module_1"
}
}
}
},
{
"logs": {
"events": {
"type": "call_action",
"attributes": {
"module": "module2"
"value": "data_value_module_2"
}
}
}
}
]
Thank you