I have an array which i am passing as input to the aggregation query
Input array:
[{
"father_id": "55c14218745aa4110082bd7e",
"son_id": "55c14218745aa4110082bd7e"
},{
"father_id": "5511c96190cb3611005261fd",
"son_id": "5511c96190cb3611005261fd"
},{
"father_id": "55ad4beeb7b72c1100bc221f",
"son_id": "55ad4beeb7b72c1100bc221f"
},{
"father_id": "55c14218745aa4110082bd7e",
"son_id": "55c14218745aa4110082bd7e"
},{
"father_id": "55c14218745aa4110082bd7e",
"son_id": "55c14218745aa4110082bd7e"
},{
"father_id": "55c14218745aa4110082bd7e",
"son_id": "55c14218745aa4110082bd7e"
},{
"father_id": "5511c96190cb3611005261fd",
"son_id": "5511c96190cb3611005261fd"
},{
"father_id": "55c14218745aa4110082bd7e",
"son_id": "55c14218745aa4110082bd7e"
}]
Aggregation Query:
[
{
'$graphLookup': {
'from': 'family',
'startWith': '$father',
'connectFromField': 'father',
'connectToField': '_id',
'as': 'family_hierarchy',
'maxDepth': 1
}
}, {
'$match': {
'$expr': {
'$in': [
'$_id', {
'$concatArrays': [
{
'$map': {
'input': [],
'as': 'relationship',
'in': {
'$toObjectId': '$$relationship.father_id'
}
}
}, {
'$map': {
'input': [],
'as': 'relationship',
'in': {
'$toObjectId': '$$relationship.son_id'
}
}
}
]
}
]
}
}
}
]
I am receiving error as follows in the atlas functions:
BadValue Unknown operator $expr
the same query perfectly executed in the compass tool.
Could you please help me with solution to match the above list.
son_id is same as _id in family collection then we have father id.
In order to make hierarchy relation i have used graphlookup and then i am trying to fetch only the list of Ids matching son_id and father_id.
there is a possibility that father may have a forefather as well but neglected for now.