M121 chapter2 Bringing it all together

would you please help me ?
Please if you want to help, don’t refer me to the manual and don’t write me essays.
Please just fix my code.

Hi @farideh_gorji.
You can not use imdb.votes as it is. Since it is a key in the document that is getting passed from the previous stage, you have to append a $ in front of it and wrap it with double quotes as:


Also, as mentioned in the handout, you have to use these values for scaling imdb.votes:

x_max = 1521105
x_min = 5
min = 1
max = 10
x = imdb.votes

So, for example, when using $subtract for imdb.votes you have to use it in the following manner:

{ $subtract: ["$imdb.votes", 5] }

I hope that helps.

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

Thanks and Regards.
Sourabh Bagrecha,


There is no output, why?
please fix my code.

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 $project everything is wrong. See $project to see why. This is what you get when you only run the $project stage:

db.movies.aggregate( { $project : { year : { $year : "$released"} } } )
{ _id: ObjectId("573a1390f29313caabcd4192"), year: null }
{ _id: ObjectId("573a1390f29313caabcd414a"), year: 1895 }
{ _id: ObjectId("573a1390f29313caabcd41a9"), year: null }
{ _id: ObjectId("573a1390f29313caabcd41aa"), year: null }
{ _id: ObjectId("573a1390f29313caabcd4136"), year: 1892 }
{ _id: ObjectId("573a1390f29313caabcd4178"), year: 2005 }
{ _id: ObjectId("573a1390f29313caabcd418c"), year: null }
/* and more documents */

As you see you only get _id and year, you do not have any other fields.

Sorry for the essay and documentation reference.


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