M121 chapter 2:last lab project

Hi ,
I tried the last lab from M121 as the following structure.I am just putting the structure not the actual code.


	     $group:{ _id:null,
		          min_vote: .......,
				  max_vote: ........,
	{$project :{
				d1 :{$subtract:["$imdb.votes","$min_vote"] },
                d2 :{$subtract:["$max_vote","$min_vote"]},
	  $sort : {......}

Project section returning null for the value “$imdb.votes”.What I am doing wrong here?
any help will be appreciated.

Hi @Barnali_Sen, welcome to the community.
MongoDB aggregation pipeline processes documents in a step by step manner.
The $group stage in your pipeline will group all the documents by the expression mentioned in the _id field of the group stage and the documents returned by this stage will be of the form

   _id: “expression for grouping”,
   field1: “calculated field based on the values of the documents getting grouped and the accumulator used like $sum, $push etc.”,
   field2: “”

Since there’s no imdb.votes field in your group stage, the imdb.votes value will always be returned as null in the project stage.

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

Thanks and Regards.
Sourabh Bagrecha,

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