1

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

Oxenarf
  • 200
  • 6
  • 23
  • Difference here is that i want to remove all the childs if the condition is verified, in the old question i just wanted to filter out inside the last array – Oxenarf Sep 19 '18 at 10:31

0 Answers0