Ch4 Lab: no overlap between top 10 rated imdb and metacritic movies?

Hi there,

Before getting into working a solution, I was trying a couple of options just to verify:

Top ten highest rated movies according to the imdb.rating

{ "title" : "Band of Brothers", "imdb" : { "rating" : 9.6 } }
{ "title" : "Dances Sacred and Profane", "imdb" : { "rating" : 9.5 } }
{ "title" : "The Third Annual 'On Cinema' Oscar Special", "imdb" : { "rating" : 9.5 } }
{ "title" : "Planet Earth", "imdb" : { "rating" : 9.5 } }
{ "title" : "The Chaos Class", "imdb" : { "rating" : 9.5 } }
{ "title" : "A Brave Heart: The Lizzie Velasquez Story", "imdb" : { "rating" : 9.4 } }
{ "title" : "Thani Oruvan", "imdb" : { "rating" : 9.4 } }
{ "title" : "Drag Becomes Him", "imdb" : { "rating" : 9.4 } }
{ "title" : "The Civil War", "imdb" : { "rating" : 9.4 } }
{ "title" : "The Shawshank Redemption", "imdb" : { "rating" : 9.3 } }

Top ten highest rated movies according to the metacritic fields

{ "metacritic" : 100, "title" : "Boyhood" }
{ "metacritic" : 100, "title" : "Fanny and Alexander" }
{ "metacritic" : 100, "title" : "The Conformist" }
{ "metacritic" : 100, "title" : "Lawrence of Arabia" }
{ "metacritic" : 100, "title" : "Au Hasard Balthazar" }
{ "metacritic" : 100, "title" : "Sweet Smell of Success" }
{ "metacritic" : 100, "title" : "The Leopard" }
{ "metacritic" : 100, "title" : "The Godfather" }
{ "metacritic" : 100, "title" : "Journey to Italy" }
{ "metacritic" : 100, "title" : "Best Kept Secret" }

If I have understood the exercise correctly, there should be overlap in these 2 top 10s, right? Where am I going wrong?

Thanks!

Bonus question: why is the order of title and metacritic switched in the second top 10 if the order in project is ‘title: 1, metacritic: 1’? How can I display title first and metacritic second?

The mongo shell is not a presentation layer. The order of the fields is not relevant. They are presented in the natural order, that is involving the least work.

The requirements are not to find the intersection of both rating system but to find best movies that have both rating.

… it was also discussed here:

Thanks for the reply. I was wondering… what constitutes as ‘best movies’? What field determines this? (if not metacritic or imdb.rating)

@007_jb Checked that thread, but it really didn’t help clarify much.

Thanks!

@Lolo_40041, the lab is asking for top 10 movies with the highest imdb rating and metacritic rating. The keyword here is and. Meaning, you should include both of them within the same aggregation stage. Makes sense?

Alright, solved it. For anyone wondering about a way to verify results, this is what I was using before:

Top 10 for imdb.rating:
db.movies.aggregate([
{$match: {$and: [{metacritic: {$ne : ‘’}}, {‘imdb.rating’: {$ne : ‘’}}] }},
{$project: {_id:0, title: 1,“imdb.rating”: 1}},
{$sort: {“imdb.rating”: -1}},
{$limit: 10}
])

Top 10 for metacritic:
db.movies.aggregate([
{$match: {$and: [{metacritic: {$ne : ‘’}}, {‘imdb.rating’: {$ne : ‘’}}] }},
{$project: {_id:0, title: 1, metacritic: 1}},
{$sort: {metacritic: -1}},
{$limit: 10}
])

Which doesn’t give out any overlap. Instead try the same with:
<check that imdb.rating & metacritic are non-zero>}

And now produce the same overlap result with facets, that’s the exercise. Comparing the top 10 of imdb and metacritic ratings in documents where both field are >0 (‘in documents where the imdb and metacritic fields are not empty’ is not a sufficient condition)

@Lolo_40041, Please edit your post it is againts forum’s policies to publish code that is possible solution for labs.

2 Likes