A document:
{
objectId: 35,
properties: [
{
pset: 'A1',
property: 'Fire',
value: '60'
},
{
pset: 'B1',
property: 'Fire',
value: '70'
}
]
}
Input to query:
{
psetsWithProperties: [{ pset: 'A1', property: 'Fire'}, { pset: 'abc', property: 'fff'}]
}
The combination of pset and property is always uniq. So there can not be two 'A1' and 'Fire' in the properties collection.
Expected output:
[{
objectId: 35,
properties: {
'A1/Fire': '60'
}
}]
So the second item (B1, Fire) is not included since it's not in the input.
If there is no match at all, the properties object is empty:
[{
objectId: 35,
properties: {}
}]
The MongoDB aggregation framework should be used here.
Something with $in, $group, $unwind I think.
Don't really know where to start.
Does not have to be exactly as in my examples.
Any ideas?
objectId: 35and do you really need to convert from'60'to60?