Lab - $facets, more detail?

Whether it is possible to specify the job in more detail?
What fields we compare:
imdb.rating and …?


(Deleted comment it was stupid…not my day)

I wrote a $facet stage with two sub-stages, one to compute imdb.rating top ten movies and metacritic ones. However, when I check for the interesection between both, no movies appear (even if I do this manually comparing the titles), but zero is not a solution for the lab.

Could anyone give another hint?


@aloplop85 - I had a similar thing going on until I realized I had made my sub-stages too complex and thus the resulting data was overly complex. Once I simplified, it was relatively smooth sailing

try sort descending by ratings

You probaly do same mistake i did.

you should try compute imdb.rating and metacritic rating on the same set of documents, having both proper imdb.rating and metacritic at the same time.


That is the key. It is necessary to match documents containing both valid fields. Thanks you gezz and @ AHarrington !


Thanks Guys, was trying the same thing.

Same problem here. Thanks!

This thread is 5 months old. Most of the people involved are not reading this forum anymore. Start a new thread with your problem.

Yep, you should have both ratings present at the same time.

@Aa_77247, you are answering to @gezz to something he posted on Oct’18. He is long gone.

Well, the thread has been ressurrected from the dead anyway, so I’ll post about it:
I solved the lab, yeah, but I thought that no way in hell that was the correct solution, and that I probably was going to solve it in a completely different manner than the proposed.
IN the end, the answer I got was very close to the one in the lab, even the field naming was close, the only big difference is that I got results by _id, and the proposed one was sorting by title, which I changed mine into when I saw it because I could then know the name of the movies.
But wow, I was confused, could not believe it was what I should have done, I think that the lessons prior to this lab could explain better the usage of the $facet stage, as there weren’t even any examples of using facets without buckets or “$let”, I even didn’t have too much hope it would work when I tried

Just in the spirit of an enhancement of this Lab in the future courses.

Why should we consider only documents with BOTH ratings at the same time? In my opinion it seems a more realistic solution filtering each field in its facet sub-pipeline.

$facet: {
    top_metacritic: [
            $match: {
                metacritic: { $gte: 0 },
            $sort: {
                metacritic: -1,
                title: 1,

Of course the result is different: zero documents in the intersection of the first 10 films.

But this happens because the solution (even the original one) depends from the ascending ordering of the documents by title, so we are cutting out documents that have the same rating of documents included in the top 10.

In fact, simply changing the direction of the title ordering, the result came back as expected.

So the solution (even the original one, i repeat) is not general, but strongly depends from the data in the collection, in particular from the title values.

Can someone see a more robust solution?


I was in same trouble, because this is not obvious from lab description

1 Like

I agree with you!
In order to find a “unique” solution you need a “unique” sort, I mean that with the sort I should obtain an unmutable order…
Sorting by title is an arbitrary solution

1 Like