M121 chapter 2 using cursor like stages



Please help to resolve the problem.
Thanks

You get an error that says num_favs is not defined. Right after the line where you seem to define num_favs with $addFields we see Uncaught:. You did not share what was uncaught. We cannot help without that. We need to know what was uncaught so that you can define num_favs correctly.



You got an invalid $addFields error that says names may not start with $.

Your only $addFields is defined as $addFields:{…cnt}.

The variable cnt is defined as {$in:[$cast,[list of actors]]}. So it starts with $in. The error indicates that names may not start with $. You have to fix that.

The general form of $addFields is

{ $addFields : {
  Field_name_that_must_not_start_with_dollar_sign : Expression ,
  Another_field_name_if_any : Another_expression
} }

Just to be clear, {$in:[$cast,list_of_actors]} is an Expression and you are missing the Field_name_that_must_not_start_with_dollar_sign part of the $addFields.