Aggregate slow on $match $expr $in

Ok, but when trying to debug performance it helps to provide the full pipeline you need to run.

Note that in 5.0 you can use simple localField/foreignField $lookup and specify additional pipeline stages for the $lookup. But even if you’re in 4.x depending on the full pipeline it might be significantly faster to rewrite it so that it can use an index for $lookup. If you provide more details, we can probably help.

Asya

3 Likes