Chapter 3 Optional Lab

Hi all,

I’m trying to figure out the meaning of the syntax in the second $project stage of the solution ie the one that creates the labor_of_love field. As per the documentation, $gt takes an integer as a value and we’re passing an array with an expression and an integer that ends up being evaluated to a boolean.

I don’t understand how the comparison between the two arguments in the array takes place within the $gt operator.

Any help will be greatly appreciated…

Franck

It looks like there are two forms of $gt:

  1. the one you describe that you’d likely see in a $match to get documents with field values greater than something, described at:
    https://docs.mongodb.com/manual/reference/operator/query/gt/index.html
  2. the aggregation version that takes an array and returns a boolean, described at:
    https://docs.mongodb.com/manual/reference/operator/aggregation/gt/index.html

The real magic in there is the size and setIntersection. That’s basically giving you the number of names in common between the cast, directors, and writers arrays. If it’s greater than 0, it’s labeled as a labor_of_love. When I was thinking through it I $projected that size/setIntersection value, and then $matched with $gt (form 1).

I am getting “errmsg” : “The argument to $size must be an array, but was of type: null”, any hel is really appreciated

First you should post your question in a new thread. The message indicates that you are using $size in the wrong context as you have not an array. Verify the syntax and if the field names are the right one.