What is wrong with my pipelines $map?


I am trying to solve the Optional Lab - Expressions with $project of chapter one.

What I’m trying to do:

  1. get rid of the second part of strings after ’ (’ in each 3 arrays
  2. mapping through the cast array values, and for each value, check if the value is in both directors and writers array.
  3. All I got from the previous code is ‘…’ prompt when running db.movies.aggregate(…).itcount()

What am I missing?

Thank you in advance for your help.

EDIT: code sample removed.

Hey @Philippe_56008

FYI I think it is best not to post any code that is even an attempted answer, as posting the answers are against forum guidelines.

However, for your

  1. You only need to do this with the writers as it states in the Lab

However, the entries within writers presents another problem. A good amount of entries in writers look something like the following, where the writer is attributed with their specific contribution

“writers” : [ “Vincenzo Cerami (story)”, “Roberto Benigni (story)” ]

  1. Using $map a little too much… From the lab

$map lets us iterate over an array, element by element, performing some transformation on each element

Transformations happen in the $project stage

$match takes a document that specifies the query conditions. The query syntax is identical to the read operation query syntax; i.e. $match does not accept raw aggregation expressions.

To deal with the issue of finding when a person appears in all 3 of the arrays it maybe best to perhaps search through the docs for a more appropriate Aggregation Pipeline operator

Hint Recall the vocabulary from Math Class :slight_smile:

1 Like