I have a collection having fields as
[
{
id: 'objectId1',
name: 'Name1',
contactInfo: {
Email: [
'first@email',
'second@email'
],
phone: [
123456
],
homeAddress: [
'address1'
]
}
},
{
id: 'objectId2',
name: 'Name2',
contactInfo: {
Email: [
'name2@email'
],
homeAddress: [
]
}
},
{
id: 'objectId3',
name: 'Name3',
contactInfo: {
}
}
]
From this , I want to create a view which has the following structure
[
{
name: ‘Name1’,
contactType: ‘Email’,
contactInfo: ‘first@email’
},
{
name: ‘Name1’,
contactType: ‘Email’,
contactInfo: ‘second@email’
},
{
name: ‘Name1’,
contactType: ‘phone’,
contactInfo: ‘123456’
},
{
name: ‘Name1’,
contactType: ‘homeAddress’,
contactInfo: ‘address1’
},
{
name: ‘Name2’,
contactType: ‘Email’,
contactInfo: ‘name2@email’
},
{
name: ‘Name2’,
contactType: ‘homeAddress’,
contactInfo: null
},
{
name: ‘Name3’
}
]
I am not able to find a way to write query using aggregation. Can someone please advise?