M121 ch2 bringing it all together

Hi, I use notepad or Visual Studio Code to save my aggregation pipelines.
It seems to me I am not executing the code in the right way in the terminal(command prompt). Either I get error or no answer.
What I do is : I copy and paste the whole code from the editor
to the terminal and press the enter .

how should I execute these multiple lines of code in the terminal to get the proper output?

The best way to find your own errors rather than relying on others over and over is to make your problem smaller. With a big aggregation pipeline you can easily remove later stages to see if what is happening is what you want and expect.

In the above case you will see that right after the first $match everything is wrong. There is no output.

We made it smaller by just keeping the $match stage. Let’s make it even smaller by testing each condition individually.

Got some output with all of

{ $match : { imdb.rating : { $gte : 1 } } }
{ $match : { imdb.votes : { $gte : 1 } } }
{ $match : { year : { $gte : 1990 } } }

But no output at all with

{ $match : { language : "English" } }

So something is wrong. Syntax is good because there is no error. So either the field name language is wrong or the value English is wrong.

So we try

{ $match : { language : { $exists : true } } }

to see that we have no input. So the field name is wrong. Then we go back to the lab’s requirement to see what is the correct name.


Thanks a lot for teaching me how to debug
an aggregation pipeline. If there are other ways
to debug please let me know.
Appreciate all your kindness.
As a mater of fact we must learn all the
useful ways to work independently and get specialized .
wish you the best


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.