Lab - Computing Fields: _id undefined

Hi, to get all the documents with title length size =1, my approach is

=> I $split the [title, " "], Then use $size to get the length, with a variable name title_size, so far so good
=> Then I added a new pipeline with $match title_size equal to 1

On the compass, it returns the result that I was expecting. But on the terminal, I am getting => Cannot read property ‘_id’ of undefined.

Does anyone know what am I missing???

Hi @Andy_Ho,

I am sharing the steps on how to approach the problem as a hint if you want to re-check your approach:

  1. It’s better, to begin with, a $match stage, so as to ensure that we only allow movies where the title is a string in our output.
  2. Next, $project stage, splitting the title on spaces using $split. This creates an array of strings.
  3. Next, you can use $match stage to filter down to documents that only have one element in the newly computed title field.

If this doesn’t help, can you please share a screenshot or your code snippet that you are entering in your terminal?

Regards,
Satyam

1 Like