My attempt at getMovieByID

Following is my attempt at the getMovieByID

static async getMovieByID(id) {
try {
Ticket: Get Comments

  Given a movie ID, build an Aggregation Pipeline to retrieve the comments
  matching that movie's ID.

  The $match stage is already completed. You will need to add a $lookup
  stage that searches the `comments` collection for the correct comments.

  // TODO Ticket: Get Comments
  // Implement the required pipeline.
  const pipeline = [{
      $match: {
        _id: ObjectId(id),

lookup: { from: 'comments', let: { 'id' : '_id’ },
pipeline: [
{ ‘$match’:
{ ‘$expr’:
{ ‘$eq’: [’$movie_id’, ‘$$id’] }
{ $sort: { ‘date’: -1 } }
as: ‘comments’

  return await movies.aggregate(pipeline).next()
} catch (e) {
  Ticket: Error Handling

  Handle the error that occurs when an invalid ID is passed to this method.
  When this specific error is thrown, the method should return `null`.

  // TODO Ticket: Error Handling
  // Catch the InvalidId error by string matching, and then handle it.
  console.error(`Something went wrong in getMovieByID: ${e}`)
  throw e


it passes json validation but does not pass the unit test. where did i go wrong? Thanks alon

Try using $lookup and let me know how it goes. If it does not work, please share the error you are seeing in the console.


I have used lookup it’s in the code i mailed

Hi @alonga281167,

Sorry to misunderstand you. I mean, you are using lookup, I want you to use $lookup.

Please try that and let me know.

  $lookup: { from: 'comments', let: { 'id' : '_id’ },


Try to reference with dollar sign
let: { id: "$_id" }

I really think the exercise should more explicitly state the comments should be stored in a field named “comments” because the video before the exercise stores them in “movie_comments”

1 Like