Using aggregation framework i would like to filter some elements inside an array based on some condition involving childs of the given array
Here there is an example of the documents
/* 1 */
{
"_id" : 1,
"articles" : [
{
"suppliers" : [
{
"exports" : [
{
"channelId" : 'A'
}
]
}
]
},
{
"suppliers" : [
{
"exports" : []
}
]
}
]
}
/* 2 */
{
"_id" : 2,
"articles" : [
{
"suppliers" : [
{
"exports" : [
{
"channelId" : 'A'
}
]
}
]
}
]
}
/* 3 */
{
"_id" : 3,
"articles" : [
{
"suppliers" : [
{
"exports" : [
{
"channelId" : 'B'
}
]
}
]
}
]
}
Let's say i want filter out all elements in articles array if 'articles.suppliers.exports.channelId' = 'A'.
Here is an example result
/* 1 */
{
"_id" : 1,
"articles" : [
{
"suppliers" : [
{
"exports" : []
}
]
}
]
}
/* 2 */
{
"_id" : 2,
"articles" : []
}
/* 3 */
{
"_id" : 3,
"articles" : [
{
"suppliers" : [
{
"exports" : [
{
"channelId" : 'B'
}
]
}
]
}
]
}
EDIT
Difference from that question is that here we want to remove all the child of the first array if the condition is verified inside the last array, in the old question we wanted to remove just the element in the last array