M121 Ch1 HW1 - SyntaxError


I’m not sure where the rouge " } " is in this $match expression. Not sure what I’m doing wrong, though it looks like even if I got the syntax correct that my operators are incorrect as well. Could someone help me?

Thank you

Seems like my issue is with multiple filters. I can create a single filter with match like this one:

But as soon as I add a second, I get this " { " error:

All I’m doing is adding a comma and another filter, what am I missing?

Hey @Nicholas_90117, it’s shaped like this:

      $match: {
         field_1: criteria_1,
         field_2: criteria_2,
         field_3: criteria_3

Can you spot the problem now?

1 Like

Thank you @007_jb for the response. I was able to create a $match aggregate with 4 and 5 different filters.

Now my questions is, how am I incorrectly filtering? I got 919, not the 23 that I’m expecting.

Couple of tips:

  1. genres filter can be merged
  2. In the context of the rated condition, $in is equivalent to $or
  3. The languages condition is not quite right. There are some operators that you need to research that weren’t discussed in any of the prior lectures. Here’s the reference.

If you do get it right, or you’re close, please don’t post it on here. :wink:

1 Like

Wow @007_jb I fixed 1 and 2 before you posted… and thank you for the link, I fixed 3.

But I still have come up with 24 instead of 23. So there’s something off i guess.

Which operator did you use for 3?

“languages”: {$all : [“English”,“Japanese”]}

Double check all the conditions, there’s something off there. Also run the validate to see if one of the answers matches.

I’ve tried a bunch of different file paths, but ever time I get [js] file doesn’t exist.

Swap the backslash (\) for a forward slash (/).

1 Like

I just got it, right be fore you replied haha… thank you, now I’m getting You aren’t returning the correct number of documents. So still working on the filters.

Clever guy :nerd_face:

Let us know how it goes.

Ok, so there’s a document with a genre of “Crime” that’s getting through. I don’t know why though.

“genres”: {$nin: [“Crime”]} <-- this is in my $match

Horror is missing :ghost:

I thought I already eliminated that possibility by separating them:

“genres”: {$nin: [“Crime”]},
“genres”: {$nin: [“Horror”]},

I’ve edited my post. It should have pointed to suggestion 1 instead of 2. The point I’m making is, you need to merge both conditions. Just like you’ve done with “$in”.

Sorry, I communicated poorly, this is what it was:

$or :[{“genres”: {$nin: “Crime”}}, {“genres”: {$nin: “Horror”}}]

same result, 24 instead of 23 docs

I understood what you wrote that’s why I’m again hinting that you need to merge both conditions.
The $or is the culprit and you only need to use one genres field, not two.

1 Like

k, got it. I would have given up so quickly without you @007_jb

On to the next lecture! Don’t get comfortable :wink: