M121 Chapter 4 Lab issues

Hi! I had issues with the lab from M121 Chapter 4.

I think this post has a few hints about the task. If this is a problem, please let me know where I can write this instead.

Issue 1

How was I supposed to infer that I should also sort by title? The task is as following at the moment of writing:

How many movies are in both the top ten highest rated movies according to the imdb.rating and the metacritic fields? We should get these results with exactly one access to the database.

Hint: What is the intersection ?

Is it a universal convention to sort lexicographically by title? Did I miss something from lectures? Please point it out.

I was confused, because imdb.rating alone does not give a clear top ten. If you do this

db.movies.aggregate([
  { $match: { 'imdb.rating': { $gte: 0 } } },
  { $sort: { 'imdb.rating': -1 } },
  { $project: { _id: 0, title: '$title', rating: '$imdb.rating' } }
])

you will see that the implied answer does not even make it to the top ten. And the 10th document has an imdb.rating of 9.3, same as 11th and 12th document, so this is unclear which document should make it to the top ten. Unless you sort by title, of course. But I was unable to infer it from the task, so here is my problem.

I decided that it is implied that I must also consider the 11th and the 12th documents, because they may also be considered to be in the top ten if you apply different sorts.

There is the same issue with the metacritic top ten.

Issue 2

I interpreted the task this way:

  1. take top 10 by imdb.rating,
  2. take top 10 by metacritic,
  3. intersect these tops.

If you do it like this, there is no intersection. You get a “correct” intersection if you first match only those documents that have both the metacritic and imdb.rating fields. But I don’t see how I was supposed to infer this from the task.


That said, I’m not 100% confident that there is a flaw in the task. Maybe I’m just reading it wrong, English is not my native language and Mongo is my first DB, so I might not be aware of some things.
Please point them out!

Thank you!

1 Like

Hi @Danylo_53477,

Issue 1 was recently discussed here.

With regards Issue 2, this has also been discussed on multiple threads with better clarity on what’s being asked. So whilst doing any of the labs. it’s recommended to search the forum if you’re in doubt or or need clarity.

Hi @Danylo_53477,

Few things to note here:

  1. Sorting according to title will improve the efficiency of intersection. However, if you skip this sort, the final result will not change.
  2. You can try to run the stages individually to check the results and verify the sort stages.
  3. Intersection is necessary to retrieve the common document from the top-10 metacritic and imdb.rating fields.

Please let me know, if you still have any questions.

Thanks,
Sonali

@Danylo_53477 i was also taken off track regarding sorting by title and still think there is a better way for sorting.

@Igor_05290 Thank you for your comment!
@007_jb The link you provided did not resolve my issues. And my point is not “I don’t understand”, it is “I think the task is not well put”. It may not be clear because I tried to be extra friendly)
@Sonali_Mamgain Yes, you did not address the issues I talked about.

To put it bluntly, The Godfather is not in the imdb top ten.

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate([ { $match: { 'imdb.rating': { $gte: 0 } } },  { $sort: { 'imdb.rating': -1 } },   { $project: { _id: 0, title: '$title', imdbRating: '$imdb.rating', metacriticRating: '$metacritic' } } ])
{ "title" : "Band of Brothers", "imdbRating" : 9.6 }
{ "title" : "The Third Annual 'On Cinema' Oscar Special", "imdbRating" : 9.5 }
{ "title" : "Planet Earth", "imdbRating" : 9.5 }
{ "title" : "The Chaos Class", "imdbRating" : 9.5 }
{ "title" : "Dances Sacred and Profane", "imdbRating" : 9.5 }
{ "title" : "Thani Oruvan", "imdbRating" : 9.4 }
{ "title" : "A Brave Heart: The Lizzie Velasquez Story", "imdbRating" : 9.4 }
{ "title" : "Drag Becomes Him", "imdbRating" : 9.4 }
{ "title" : "The Civil War", "imdbRating" : 9.4, "metacriticRating" : null }
{ "title" : "The Real Miyagi", "imdbRating" : 9.3 }
{ "title" : "The Shawshank Redemption", "imdbRating" : 9.3, "metacriticRating" : 80 }
{ "title" : "Cosmos", "imdbRating" : 9.3 }
{ "title" : "RangiTaranga", "imdbRating" : 9.2 }
{ "title" : "Over the Garden Wall", "imdbRating" : 9.2 }
{ "title" : "Henry Gamble's Birthday Party", "imdbRating" : 9.2 }
{ "title" : "Frozen Planet", "imdbRating" : 9.2 }
{ "title" : "Human Planet", "imdbRating" : 9.2 }
{ "title" : "Life", "imdbRating" : 9.2 }
{ "title" : "The Blue Planet", "imdbRating" : 9.2 }
{ "title" : "The Godfather Trilogy: 1901-1980", "imdbRating" : 9.2 }

Unless you also match for movies that have a non-null metacritic field.

MongoDB Enterprise Cluster0-shard-0:PRIMARY> db.movies.aggregate([ { $match: { 'imdb.rating': { $gte: 0 }, 'metacritic': { $gte: 0 } } },  { $sort: { 'imdb.rating': -1 } },   { $project: { _id: 0, title: '$title', imdbRating: '$imdb.rating', metacriticRating: '$metacritic' } } ])
{ "title" : "The Shawshank Redemption", "imdbRating" : 9.3, "metacriticRating" : 80 }
{ "title" : "The Godfather", "imdbRating" : 9.2, "metacriticRating" : 100 }
{ "title" : "The Martian", "imdbRating" : 9.1, "metacriticRating" : 72 }
{ "title" : "The Godfather: Part II", "imdbRating" : 9.1, "metacriticRating" : 80 }
{ "title" : "The Dark Knight", "imdbRating" : 9, "metacriticRating" : 82 }
{ "title" : "The Century of the Self", "imdbRating" : 9, "metacriticRating" : 80 }
{ "title" : "The Power of Nightmares: The Rise of the Politics of Fear", "imdbRating" : 8.9, "metacriticRating" : 78 }
{ "title" : "The Lord of the Rings: The Return of the King", "imdbRating" : 8.9, "metacriticRating" : 94 }
{ "title" : "Fight Club", "imdbRating" : 8.9, "metacriticRating" : 66 }
{ "title" : "Pulp Fiction", "imdbRating" : 8.9, "metacriticRating" : 94 }
{ "title" : "Schindler's List", "imdbRating" : 8.9, "metacriticRating" : 93 }
{ "title" : "The Good, the Bad and the Ugly", "imdbRating" : 8.9, "metacriticRating" : 90 }
{ "title" : "Born to Be Blue", "imdbRating" : 8.8, "metacriticRating" : 66 }
{ "title" : "Inception", "imdbRating" : 8.8, "metacriticRating" : 74 }
{ "title" : "The Lord of the Rings: The Fellowship of the Ring", "imdbRating" : 8.8, "metacriticRating" : 92 }
{ "title" : "Forrest Gump", "imdbRating" : 8.8, "metacriticRating" : 82 }
{ "title" : "Star Wars: Episode V - The Empire Strikes Back", "imdbRating" : 8.8, "metacriticRating" : 79 }
{ "title" : "Symphony of the Soil", "imdbRating" : 8.7, "metacriticRating" : 63 }
{ "title" : "Interstellar", "imdbRating" : 8.7, "metacriticRating" : 74 }
{ "title" : "City of God", "imdbRating" : 8.7, "metacriticRating" : 79 }

But the task does not specify that condition: only make top tens out of the docuements with both ‘imdb.rating’ and ‘metacritic’ fields. The resolution would be to reword the task.

1 Like

That was not the point of the thread. The observations from that thread states that because of the dataset that’s used in the lab, there’s no difference in result if you include or exclude the $sort. You can test this out for yourself. In any other dataset, the result may differ and a sort will be necessary.

The observations from that thread also infers that the lab requirement did not explicitly state that a sort was required and as a result the solution should not have included a $sort. If a sort was required, the requirement should have explicitly stated that… we’re agreeing on this same point.

Again, that was not the point of the sound advice that I gave. This same lab has been completed by countless number of people before you and as a result they have sought clarity on this matter via the forum. In those threads, many students have complained about/reported the same thing you’re talking about and consequently there has been clarity/tips on exactly what is being asked for.
If you fail the first try, it only makes sense to search the forum to see if someone else has interpreted it differently from you.

I agree that the lab should be re-worded, and the same has been reported to the Curriculum Engineers. But in the meantime, one can find clarity/hints/tips by searching the forum.