Chapter 1 - Optional Lab

Hi, someone know to do the last lab (optional) ?

Optional Lab - Expressions with $project

Hi,

Just a hint: $setIntersection is very handy for this lab. The answer will be available once the due date has passed.

José Carlos

4 Likes

Thank you. I have a few experience with mongo, then I dont remember all functions, that are many.

I will try, I dont want the answer.

I can !!! Thank you.

I got stuck on this one. I tried to wrap around my head and couldn’t. Eager for an explanation.

Hey Jose,

Could you go over how to answer this?

Hi,

There’s an answer available in the quiz page. Here’s the link if you can’t find it.

[LINK REMOVED]

Hope this helps.

José Carlos

Hi,
I received another outcome 1259 (which is also available to select).
correct answer is
pipeline = [ {$match: …}, {$project:…}, {$project: … {$setIntersect: …}}, {$match:…} ]
I combined two consecutive $project into one. why it is wrong, why we need separate $project for $setIntersect ??? any help or hint
thanks,

Hi,

That’s because the second projection uses a new field projected on the previous one (writers). You cannot do that in a single stage unless you use the $let expression.

José Carlos

Hello,

I’m getting the 1259 answer particularly using $setIntersection and then (perhaps a little too) briefly speaking $match.

My question(s):

  • (first, should the above discussion be available for this (next) cohort too at all? :slight_smile: )
  • then, is it really the incorrect answer? could I share the pipeline in some legit way with you - if you were kind enough to have a quick look just to see if it’s really wrong? (just as a yes/no)

Thank you!

Hi,

You are right, just removed the link I posted for a previous round of the course. I’ve reached you via email so that you can send me your query to take a look.

José Carlos

Thank you for the hint. I did wonder why that made a difference, until I properly read what it did.

As always the lesson was read the operator desciption properly :slight_smile:

Hello, can you please explain further this point?

  • Why are any results available if combining the projections is invalid?
  • What is different about these 1,259 results than the other ones that don’t match?
  • How would a developer be sure to provide valid results when another result set seems to match?

I think I get it now. There are 1,259 results that match the original “writers” field, and the remaining ones have “(story)” or some such.

1 Like

:+1: You are right. I forget this thing too.

1 Like