I am trying to make a pagination and use the countDocuments() method to return the total number of documents that would only match to all teams who’s leader is under the organization of DC.
Teams Collection
{
_id: 1,
name: 'avengers',
leader_id: 'L1'
},
{
_id: 2,
name: 'justice league',
leader_id: 'L2'
},
{
_id: 3,
name: 'suicide squad',
leader_id: 'L3'
}
Leaders Collection
{
_id: 'L1',
name: 'ironman',
organization: 'MCU'
},
{
_id: 'L2',
name: 'superman',
organization: 'DC'
},
{
_id: 'L3',
name: 'harley quinn',
organization: 'DC'
}
My question is, is it possible to perform $lookup aggregation to mongoDB’s countDocuments() to match the documents from 2 collections?