M220N Facets Pipeline

I am running the TestFacets and I get the following error:
Expected 20 But was 21

Looking at the TestFacets method, it appears that I am failing the first movie query where it expects 20 movies but I am getting 21…

No idea how to debug this as I cannot view my output in the current system…

I do want to ask this… I am unfamiliar as to where to put the stages so I looked at it this way…
As I understand the lab, the first two stages are done for me… My question is whether I can move the matchStage and sortStage?

I currently believe it should go match, sort, facet, limit, and page but I am not sure… How can I get info on this order?

I cannot go any farther in the class until I can get some advise on how to troubleshoot this… Where I am struggling is in the aggregations class, I could always break my query into smaller steps and check my output… It doesn’t seem to be this way in the .net course.

Your lab states that I only need to put in the missing stages, and to think of where to put the $facet stage. However, I have tried every combination and I am getting 1 more document back than is expected and I don’t know of a way to troubleshoot this using the vs code given.

Help please.

Hi @David_Thompson, apologies for the delayed response.
Please be rest assured that we looking into this and we will surely get back to you by the end of the day.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Hi @David_Thompson, hope you are doing well.

No, you don’t have to move them, match & sort are already in their expected order & position.

The easiest way to test your aggregation pipeline and troubleshoot the output is by using MongoDB Atlas Aggregation Pipeline Builder.
You can reproduce the pipeline mentioned in the GetMoviesCastFacetedAsync function and this would hopefully give you an idea about how and what documents are getting passed at every stage. You can edit the pipeline as per your requirement in the builder.
Also learn more about pipeline optimization.

Please note that whenever we are implementing pagination we always skip before limiting the result, doing the opposite can result in inconsistencies and unexpected output.
Also as per $facet documentation:

Each sub-pipeline has its own field in the output document where its results are stored as an array of documents.

Hence $facet usually contains the final results/output, and it would be better to have $facet as last as possible.
Therefore the correct sequence would be: skip -> limit -> facet
In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer

Your test passes, but when I enter the search for Tom Hanks, there isn’t any fields added to the top… Attached is a screenshot of the front end. Is this correct?

As you can see the first movie doesn’t star Tom Hanks… The second and subsequent ones do, but there isn’t any real limitation of the display to the search results. Of course I searched by text not cast

Upon switching to cast I get these results.

Why is it that if I search by any other method (Text, Country, Genre) the results are wrong?

Hi @David_Thompson, if you search by text, the $text operator will be used in the backend, and it will tokenize the search string using whitespace and most punctuation as delimiters, and perform a logical OR of all such tokens in the search string.
Therefore the query: "Tom Hanks" will be tokenized into two such tokens, and all the movies having "Tom" or "Hanks" or both will be returned.

In case you are wondering how to search for the exact phrase, I would recommend you to go through the Exact Phrase documentation and take a look on how you can achieve the same.

In case you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,
Curriculum Services Engineer