I have the Collection with the below data.
{
mytoken: 'foo',
attributes: [
{ attribute: 'Attr-A', value: 'value-for-a', op: ':=' }
{ attribute: 'Attr-B', value: 'value-for-b', op: ':=' },
{ attribute: 'Attr-C', value: 'value-for-c', op: '-=' },
{ attribute: 'Attr-D', value: 'value-for-d', op: '+=' },
{ attribute: 'Attr-E', value: 'value-for-e', op: ':=' }
]
}
Therefore, I’d to get only the ‘attributes’ array result based on which attributes values I want.
e.g: I was trying something like…
// It doesn't work
[[
{
"$match":{
"mytoken":"foo"
}
},
{
"$addFields":{
"attributes.Attr-C":"$value",
"attributes.Attr-E":"$value",
}
},
{
"$project":{
"_id":0,
"attributes":{
"$objectToArray":"$attributes"
}
}
},
{
"$unwind":"$attributes"
},
{
"$project":{
"_id":0,
"attribute":"$attributes.k",
"value":"$attributes.v",
"op":"$op"
}
}
]]
My goal is to have a result like this:
[
{ attribute: 'Attr-C', value: 'value-for-c', op: '-=' },
{ attribute: 'Attr-E', value: 'value-for-e', op: ':=' }
]
and also a possibility to get the entire attributes: []
array.
Appreciate any help.