I have a aggregation function in which there are nested lookups with pipeline. In one of the pipeline I have the following -
{
"$addFields": {
"ids": {
"$split": ["$id", ","]
}
}
},
{
"$lookup": {
"from": 'collection2',
"let": {"new_id": "$ids"},
"pipeline": [
{ "$match": {
"$expr": {
"$in": ["$ID", "$$new_id"]
}
}
}
],
"as": 'groups'
}
}
In the above pipeline addFields is splitting the comma separated value in "id" and adding it to an array named "ids".
This "ids" I am using it in lookup below to find the data from other collection using "$in".
But I am getting this error in MongoDB Compass - $in requires an array as a second argument, found: null.
I tried the same by using just this pipeline in a separate aggregation pipeline in Compass where I am getting the results properly but when I include the same in my nested lookup pipeline its not working and giving the above error.
Is it because of nesting or any local variable or any other issue?