Inner join ($lookup then $match) performance

Hello!

After reading chapter 6, I wonder about $lookup performance in case of an inner join scenario. Is it more performing to:

  • either decouple the steps:
    {
       $lookup:
         {
           from: < collection to join >,
           localField: < field from the input documents >,
           foreignField: <field from the documents of the "from" collection>,
           as: < output array field >
         },
      $match:
       {
         < expression >
       }
    }
  • or couple the steps:
    {
       $lookup:
         {
           from: < collection to join >,
           let: { <var_1>: < expression >, …, <var_n>: < expression > },
           pipeline: [ < pipeline to execute on the collection to join > ],
           as: < output array field >
         }

Hey @Antoine_Delequeuche,

Thanks for reaching out to us!!

I would recommend you to go through the Documentation: Aggregation Pipeline Optimization

This will give you an idea of the placement of pipeline stages. If you still have any questions, please feel free to reach out.

Kind Regards,
Sonali Mamgain