Ticket: Create Update comments

This is my code:

static async updateComment(commentId, userEmail, text, date) {
try {
// TODO Ticket: Create/Update Comments
// Use the commentId and userEmail to select the proper comment, then
// update the “text” and “date” fields of the selected comment.
const updateResponse = await comments.updateOne(
{ “_id”: ObjectId(commentId), “email”: userEmail },
{ $set: { “text”: text, “date”: date}},
)

  return updateResponse
} catch (e) {
  console.error(`Unable to update comment: ${e}`)
  return { error: e }
}

}

It fails the second test: Can update comment

I can’t see what is wrong with my code. PLEASE HELP

Hi @Duncan_66850,

The code seems right. Please share the screenshot of the console when you run the unit test-case.

You might be seeing some message around the fail message.

Kanika

Can only do this when I get home from work which will be too late for the cut off. There is no indication as to why the middle test failed and the other 2 passed. Just say expected 1 and got zero. I read about some issues with timing out. And having to change some timeout setting somewhere but not sure where to do this. I am in Africa where the internet is slow and my cluster is in America.

I just hope I have done enough to pass. Hopefully if I can get 100% for the Exam and the last chapter then I can pass. I tried doing the rest of the tickets too but none of them passed completely either and I am pretty sure my code is good.

Hi @Duncan_66850,

It is very hard for me to assume or check without looking at anything.

That means the code is unable to update the comment. There are so many things that can cause the issue:

  • Check the code for Get comments
  • Make sure sorting is there wherever required
  • The data you have imported is correct and complete.

Kanika

I have checked my code against the solution and it is exactly the same yet it still doesn’t pass the test. This is not fair.

May be your data is altered, you could try reloading the data from the supplied course material. Or may be some some code else where is wrong. Do you sort the comments?

I have exactly the same problem and the same screenshot.
I already tried:

  1. Write the code with multiple combinations of ', ", ObjectId (), new ObjectId ().
  2. I restored the data and re-executed the tikets in order, all successful except Create / Update Comments
  3. Check via Mongo Atlas and Mongo Compass that the comment is not being inserted in the comments collection although Can post a comment is successful

I already lost the dates of this course and I want to solve the problem so as not to lose the next edition but I did not achieve it despite the time invested.
Any suggestions, ideas, experience?

Do you sort the comments in getMovie as asked in the requirements?

Yes, the tiket that check getMovie with comments ordered pass successfully.

Please read the following

and many other threads where people had similar problem.

Is possible get unordered comments if the tiket that check getMovie with comments ordered pass successfully?

I did the following:

  1. Print the returning comment id on Create Comment test that pass successfully, I get a correct id.
  2. Went to Atlas and Compass and did a filter in comments collection: { _id : ObjectId(returnedId) } and nothing is returned. Here is the problem ! , Why Create Comment is ok , and why Update Comment not ?

There is a little glitch in the unit test where the test comments are ordered correctly and if you do not sort them, getMovie still works because the natural order matches the required order. In update comment the date is changed and the natural order does not matches the required order anymore.

1 Like

Yes, it returns the comments ordered.
I included the following in the pileline, I tested it in Compass Aggregation Editor.
…, {’$ sort’: {date: -1}}]

Hi @amackiew,

Please check your messages. :slight_smile:

Kanika

Hi Steeve, I’m having the same problem with the Ticket: Create Update Comments

At the getMovies(), my sort is declared as DEFAULT_SORT, should it be -1?

let { query = {}, project = {}, sort = DEFAULT_SORT } = queryParams

The task reads as

The comments should be returned in order from most recent to least recent using the date key.

So what do you conclude? But what ever the conclusion you risk nothing by trying.

The getMovieByID(), I think is correct!

const pipeline = [

    {

      $match: {

        _id: ObjectId(id)

      }

    },

    {

      $lookup: {

        from: 'comments', 

        let: {

          id: '$_id'

        }, 

        pipeline: [

          {

            $match: {

              $expr: {

                $eq: [

                  '$movie_id', '$$id'

                ]

              }

            }

          }, {

            $sort: {

              date: -1

            }

          }

        ], 

        as: 'comments'

      }

    }

  ]

But do I have to also sort descending on getMovies()