How to get intersection data of a field from multiple Mongodb document's field's data. Want a Mongo aggregate Fuction which I can add in my query

0

I am already using a Mongo db Aggregate Query to get a array of output. email will be the array of emails as input in the query.

**aggregateQuery** = [
{
    '$match': {
        'email': {
            '$in':

                ['abc@testmail.com', 'xyz@testmail.com', 'qwe@testmail.com']
        },
        'deleted': false
    }
},
{< Some more logics here >},

    { '$project': { 'email': 1, 'refId': '$dataArray._id' } }
];


**Current Output**: [
    {
        _id: 't1',
        email: 'abc@testmail.com',
        refId: ['ref1', 'ref2', 'ref3','ref4','ref5']
    },
    {
        _id: 't2',
        email: 'xyz@testmail.com',
        refId: ['ref1', 'ref2','ref5',ref'82']
    },
    {
        _id: 't3',
        email: 'qwe@testmail.com',
        refId: ['ref2', 'ref5','ref77']
    }
]

So now I want to update my query so that it gives common (or intersection) refids as output keeping in mind input (or output) is not limited to 3.

**Expected Output** : [
Common_RefIds:['ref2', 'ref5']
]