How can i use merge array to a new array from a detail document there is an example of data
Example of result detail
[{
country: 'USA',
val: 500,
items: [
{val:50, ...manyFieldsToIgnore},
{val:30, ...manyFieldsToIgnore},
{val:110, ...manyFieldsToIgnore},
]
}];
Output expected
{ items:[
{
country: 'USA',
newNameValue: 500,
},
{
country: 'USA',
newNameValue: 50,
},
{
country: 'USA',
newNameValue: 30,
},
{
country: 'USA',
newNameValue: 110,
},
};
im try to use $project and $concatArrays but i dont know how to set the new field(country) in details and change their key names
$project: {
'root.country': '$country',
items: concatArrays[ '$items'],
},
$project: {
payments: concatArrays[ '$items', ['$root'] ],
}