Chapter 1 computing fields

Atlas Cluster0-shard-0 [primary] aggregations> db.movies.aggregate([ {$project:{ arrayOfWords: {$split : ["$title"," "]},
… noOfWords: {$size: arrayOfWords}
… } },
… {$match: {
… noOfWords: {
… $eq: 1
… }}} ]).itcount()
ReferenceError: arrayOfWords is not defined
Atlas Cluster0-shard-0 [primary] aggregations>
please help me on this.

Edited to correct some misspelling mistakes.

Please refer to the $size documentation for the correct syntax.

There are 3 issues:

  1. you are not using double quotes, arrayOfWords is not a variable it is a field name
  2. you are not using the double sign in front of arrayOfWords to indicate you want the value of the field
  3. fields created with $project, $addFields or $set are only available in the next stage

I am petty sure that your question is not related to Hackathon '22. Make sure you create your post in the appropriate forum’s section. For which course are you doing this query?