I’m having performance issue on a big aggregation query with multiple $lookup to retrieve data between different collections.
Trying to investigate I’ve found that one of the slower stages is using a $match - $expr - $in on a indexed field, but trying to isolate and analyze that stage with explain
it result a COLLSCAN and not an IXSCAN.
The stage is something like:
{
'$lookup': {
from: 'othercollection',
let: {
inputarray: '$inputarray'
},
pipeline: [{
'$match': {
'$expr': {
'$in': ['$_id', '$$inputarray']
}
}
},
.....
I’ve found this old issue, trying to found a solution over here https://jira.mongodb.org/browse/SERVER-32549: is the situation still the same on 4.4 ?
If an index cannot be used, do you have any suggestion of how to transform the query?