Chapter 1 : Optional Lab - Expressions with $project

I built the same type of query each in a different project and then I combined/optimized it. When I did this I landed up in query like this

code removed

One thing I observed here is this is the same as the answer except that the “labors of love” is projected in the first $project whereas in the answer it is done in the second $project. Due to this difference the answer is varying. I did not understand why so. Can anyone please explain???
Note : Please compare the above query with the actual answer to find the difference as described above.

Hey @Sourabh_Karmarkar

Just FYI it is against forum guidelines to post any answers or potential answers to the labs or final exam. I know this is a optional lab but I still think you should remove your code. :slight_smile:

To whom should I ask my doubt? For that I need to show the query!

Yeah that is the tough part…

Is your pipeline query returning the correct answer?

I would guess that it has to do with the writers field and having to strip off the ‘(story)’ part; from the Lecture

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)" ]

No. The result is varying

There is no difference in the writers field. Just move the 2nd $project from the answer in the first $project itself and try to run the query. I mean combine the $project and add it to the end of 1st $project. You will notice that the answer is varying! I cannot understand why so!!

@Sourabh_Karmarkar

If you think about it, the “labors_of_love” needs to be in a separate stage, since the full value of “writers” is not completely calculated until the first stage of the pipeline is completed. Therefore trying to put that into the first stage will never give you a consistent answer.

1 Like

Ok got it!! That means all the calculations in a single stage happen in different threads and hence put it in the second $project to ensure that all the calculations are completed in the first $project?

A bit confused about the expression [ movies are “labors of love”]. Is “labors of love” a movie title?

1 Like

Hi @xixis, “Labor of love” or “Labour of love” is just an expression which means “doing something without expecting a reward”. It’s not a movie title so ignore that sentence.