Using query aggregation I want to create a new array by a filter of another array, so that the filtered result will be done by a specific field of the preliminary array. In this case, I want to filter by the field "fieldName".
I will always want to filter out the last occur
example: I have one document:
{
"fullyQualifiedName" : "MongoDB",
"items" : [
{
"fieldName" : "_id",
"fieldCount" : 7,
"confidence_level" : 1,
"fieldClassifications" : [
"LineageGuid"
],
},
{
"fieldName" : "_id",
"fieldCount" : 7,
"fieldClassifications" : [
{
"classificationName" : "LineageGuid",
}
]
},
{
"fieldName" : "details",
"fieldCount" : 7,
},
{
"fieldName" : "state",
"fieldCount" : 7,
}
]
}
I want to create a new array like:
"items" : [
{
"fieldName" : "_id",
"fieldCount" : 7,
"confidence_level" : 1,
"fieldClassifications" : [
"LineageGuid"
],
},
{
"fieldName" : "details",
"fieldCount" : 7,
},
{
"fieldName" : "state",
"fieldCount" : 7,
}
]
The simple solution is to $unwind and $group again but I can't do it because of performance issue. I am using MongoDB 3.4