I have documents having the following schema:
[
{
"documentKey": "documentData",
"functions": [
{
"name": "firstFunction",
"outerArray": ["elements", "in", "the", "array"],
"objectsToBeFiltered": [
{
"objectName": "firstObject",
"innerArray": ["elements", "in", "the", "array"],
"columns": ["a", "b"]
},
{
"objectName": "secondObject",
"innerArray": ["elements", "in", "the", "array"],
"columns": ["z"]
}
]
},
{
"name": "secondFunction",
"outerArray": ["elements", "in", "the", "array"],
"objectsToBeFiltered": [
{
"objectName": "firstObject",
"innerArray": ["elements", "in", "the", "array"],
"columns": ["m"]
},
{
"objectName": "secondObject",
"innerArray": ["elements", "in", "the", "array"],
"columns": ["a"]
}
]
}
]
}
]
I want to discard elements of objectsToBeFiltered
array without "a"
in columns
I have gone through this SO answer for a similar problem but replicating it has not worked out for me: Mongo Playground. I end with empty objectsToBeFiltered
array for all objects in functions
array.
My expected output is:
[
{
"documentKey": "documentData",
"functions": [
{
"name": "firstFunction",
"outerArray": ["elements", "in", "the", "array"],
"objectsToBeFiltered": [
{
"objectName": "firstObject",
"innerArray": ["elements", "in", "the", "array"],
"columns": ["a", "b"]
}
]
},
{
"name": "secondFunction",
"outerArray": ["elements", "in", "the", "array"],
"objectsToBeFiltered": [
{
"objectName": "secondObject",
"innerArray": ["elements", "in", "the", "array"],
"columns": ["a"]
}
]
}
]
}
]