Chapter 1 Optional Lab solution question

Chapter 1: Basic Aggregation - $match and $project
Optional Lab - Expressions with $project

I tried this solution:

  1. In the stage1 ($match), I am checking that the writers, cast and directors fields exist
  2. In stage2 ($project), I am transforming the writers to remove the text with " (…)"
  3. In stage3 ($project), I am using $map on cast and for each cast member I am checking if exists in ($in) the transformed writers and the directors arrays. The newly created array of booleans are stored in a new field, matched.
  4. In the last stage ($match), checking if matched field from previous stage has a true element.

Finally, the itcount gives the result correctly.

Is this solution acceptable? I see the actual answer uses different solution (I had no idea such array element comparison operator existed). Is there a disadvantage to the solution I made? If so what are they?

Thanks,
Prasad.

P.S.: I hope I am not breaking this rule: " [NOTICE] Please do not post potential answers in the forums"

@Prasad_45636

Well, it’s coming close, but I’m going to allow it :wink: since this is an optional lab and since you’re being good about noticing that it’s skirting the line.

Your solution seems fine to me and, since it gives the correct answer is clearly acceptable. I’d suggest that it’s probably – I haven’t run any tests on it BTW – a bit more complex and therefore less optimal in terms of performance, but since this is a one-off, that’s really not much of an issue. Good luck.