Hi, first of all thanks for your reply:
First of all, I understand that the num of favorites AND tomatoes.viewer.rating AND title needs to be sorted decending, so num of favorites from 2 to 0, rating from 10 to 1 and title from Z to A .
Country of release should be USA, but that does not mean ONLY USA. So as long USA is in the list of countries thats fine. tomatoes.viewer.rating should be equal to 3 or higher.
I also made sure that cast exists, and that there is at least one element in the array, otherwise there is no point in comparing the cast with the favorites array.
Debugging wise I did the following,
As a last stage, I have put a match in again in again, so can double check my findings:
db.movies.aggregate([
{ $match : { cast: { $exists: true, $not: {$size: 0} } , "tomatoes.viewer.rating": {$gte:3} , countries: { $elemMatch : {$eq: "USA"} } } } ,
{ $project: { _id:0, title:1 , countries:1 , "tomatoes.viewer.rating":1, cast: 1 , commonToBoth : {$setIntersection: [ [
"Sandra Bullock",
"Tom Hanks",
"Julia Roberts",
"Kevin Spacey",
"George Clooney"] , "$cast" ] } } } ,
{ $match : { ......... } } ,
]).pretty()
So in the last stage of the pipeline, the 2nd $match, I put as follows:
countries: {$size:2}
Seems I have always USA in my list, sometimes on first sometimes on second place- check .
"tomatoes.viewer.rating": {$lte:3}
Seems I am only getting movies with rating 3 now, check.
commonToBoth: {$size:2}
My commont to both field shows 2 actors as expected (only names which are common to both lists) - check.
So, if I store the size of commonToBoth into num_favs, as per my very first post , and then sort as follows:
$sort : {num_favs: -1 , "tomatoes.viewer.rating":-1, title:-1}
I would have expected the 25th entry is the one I need?
Appreciate that I am overlooking something - but seriously - I am blind at the moment 