Issue Optional Lab - Expressions with $project

How many movies are “labors of love”?
Here is my pipeline, can someone help me

[
  {
   '$match': {
         '$and': [
                    {
                     'cast': {'$elemMatch': {'$exists': true}}
                    }, {
                     'directors': {'$elemMatch': {'$exists': true}}
                    }, {
                     'writers': {'$elemMatch': {'$exists': true}}
                    }
                ]
          }
  }, {
'$project': {
  '_id': 0, 
  'cast': 1, 
  'directors': 1, 
  'writers': 1, 
  'common': {
    '$setIntersection': [
      '$cast', '$directors', '$writers'
    ]
  }
}
  }
]

What are the results you are getting?

Have you look at the fields cast, directors and writers to see if their content can generate a non empty intersections?

1 Like

In the 1st stage I’m checking if the field exists, so that matches if there is a value in a field

I get labors of love : 40825

I’m struck at eliminating the empty array of $common

“Douglas Fairbanks”

Look at document { _id : 573a1391f29313caabcd7d4e }.

The value of cast.0 is “Douglas Fairbanks” and the value of writers.1 is the same but written as “Douglas Fairbanks (story)”. The intersection will be empty between cast and writers because they are not written the same.

I do not understand what you want to do by

This I didn’t expect, I was getting the common name by intersection. I’m able to count the size of common attribute, but I couldn’t check if it is an empty array or not.