MongoDB countDocuments() with lookup

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?

Hi @Jayvee_Mendoza, there is no specific method to count documents in a collection which have matching documents (EDIT ADD: in another collection). The aggregation’s $lookup operation is a way to go with. Otherwise, you may have to write two individual queries.