Can someone explain what am I missing in the below query. I get 1259 as the answer for this Question
pipeline = [
{
"$match": {
"cast": {"$elemMatch": {"$exists": True}},
"writers": {"$elemMatch": {"$exists": True}},
"directors": {"$elemMatch": {"$exists": True}}
}
},
{
"$addFields": {
"writers": {
"$map": {
"input": "$writers",
"as": "writer",
"in": {
"$arrayElemAt": [
{"$split": ["$$writer", " ("]},
0
]
}
}
},
"common": {
"$size": {"$setIntersection": ["$cast", "$directors", "$writers"]},
}
}
},
{
"$match": {
"common": {"$gt": 0}
}
},
{
"$count": "count"
}
]