Basic Joins Video Code

This is not an easy ticket, you need to read the instructions as detailed in the file.

But as a hint, you need to brush up on mongo aggregation skills and remember that it’s a multi layer of filtering, lookup and the array structure of comments that is joined to the movies need to be “sorted”. You can’t sort the array element on an object that is an array.

Regards

1 Like

Sorry @bdanalytics, but I think the $sort is at the right place because it is in the pipeline inside the $lookup and at this point the comments are still in the collection and are not in the array.

It would help to have the error messages you get.

3 Likes

this is the error i get:

Get Comments
✕ Can fetch comments for a movie (72ms)
✓ comments should be sorted by date (714ms)

● Get Comments › Can fetch comments for a movie

expect(received).toBe(expected) // Object.is equality

Expected: 2
Received: 0

  11 |     const movie = await MoviesDAO.getMovieByID(id)
  12 |     expect(movie.title).toEqual("Once Upon a Time in Mexico")
> 13 |     expect(movie.comments.length).toBe(2)
     |                                   ^
  14 | 
  15 |   })

Hi @Ellie_43912,

Thank you for taking the time to post the aggregation from the lecture here!

As it turns out, I had the correct pipeline the whole time. I just had the wrong title assigned to the outgoing/newly created as array.

I need to work on my testing skills, as it appears that I should have picked out the proper name from get-comments.test.js right away.

…feeling a bit silly at the moment, but grateful. :rofl:

Thanks again!

@Alessandro_65603, the error from the test case tells that you have returned 0 comments while it expected to get 2. This probably indicate an issue with $match but I cannot pinpoint it right away.

Hi @Alessandro_65603,

Maybe check your connection to the Atlas cluster? Maybe there was a timeout. I’m guessing in the wind, but try restarting your connection. Other than that, I can’t understand why your code is failing, especially having made the adjustments that @Ellie_43912 suggested.

1 Like

Hi !
the error tell me this ✕ Can fetch comments for a movie (83ms)
But ✓ comments should be sorted by date (1057ms)
It 's able to sort comments in second part of test but not able to fetch comment once the id of a movie is given…

Good catch. At this point I would try the whole pipeline in Compass by replacing the first $match to get at the same movie they use. This might help finding which part has an issue. I would also make sure that the comments are really in there. It is possible that your dataset has been altered.

1 Like

Thank you @Sotiria_19090! That is exactly what I was missing. :grinning:

2 Likes

I resolved, i restore the db using mongorestore … Now all goes ok!!!

Thanks to all !!! :grinning::grinning::grinning:

Hello Ellie,
I’m gonna weigh in here and endorse your complaint about the video in this section and I’m going to offer further observations.
I am visually impaired. This lesson was a disaster. Even in full screen mode, the print was tiny and washed out, barely readable.
It looks to have been recorded on a large screen device, perhaps >= 26". Many of us are viewing this material on smaller screens, In my case a 17" laptop with a more rectangular 17" auxiliary screen. The image gets squished and becomes really difficult to see. I am grateful to those who offered the correct code so I could find my problem. As you suggest, much confusion could be avoided if the code snippets where provided in text form.
I do hope the Mongo people might consider rerecording this lesson.

1 Like