I am working with MongoDB aggregation framework:-
I have a movie collection database which looks like this:-
{'_id': ObjectId('573a1390f29313caabcd4192'),
  'title': 'The Conjuring of a Woman at the House of Robert Houdin',
  'year': 1896,
  'runtime': 1,
  'cast': ["Jeanne d'Alcy", 'Georges M�li�s'],
  'plot': 'A woman disappears on stage.',
  'fullplot': 'An elegantly dressed man enters through a stage door onto a set with decorated back screen, a chair and small table. He brings a well-dressed women through the door, spreads a newspaper on the floor, and places the chair on it. She sits and fans herself; he covers her with a diaphanous cloth. She disappears; he tries to conjure her back with incomplete results. Can he go beyond the bare bones of a conjuring trick and succeed in the complete reconstitution of a the lady?',
  'lastupdated': '2015-08-26 00:05:55.493000000',
  'type': 'movie',
  'directors': ['Georges M�li�s'],
  'imdb': {'rating': 6.3, 'votes': 759, 'id': 75},
  'countries': ['France'],
  'genres': ['Short'],
  'tomatoes': {'viewer': {'rating': 3.7, 'numReviews': 59},
   'lastUpdated': datetime.datetime(2015, 9, 11, 17, 46, 29)}}
I have written the query:-
'$project': {
    'num_favs' : { 
        '$setIntersection' : [favorites, '$cast']
    },
    'tomatoes.viewer.rating' : 1,
    'title' : 1
}
It will return the set intersection of favorites array and cast field of my data along with 2 other fields. My favorites array looks like this:-
favorites = [
  "Sandra Bullock",
  "Tom Hanks",
  "Julia Roberts",
  "Kevin Spacey",
  "George Clooney"
]
What I want is that the field num_favs to be the size of the set returned by $setIntersection method.
I am unable to figure out how to find the size of the returned set. Can anyone please provide me with a solution to this?
 
    