Create-Update-Delete Comments

Hi all,
I’m stuck with Comments section, cannot pass test.
Here is my code.
const commentDoc = {
movie_id: ObjectId(movieId),
text: comment,
date: date
return await comments.insertOne(commentDoc)
Test result - FAILED:
● Create/Update Comments › Can post a comment


Expected value to equal:


- Expected
+ Received

- "5cb76fa9c35ffb309852756b"
+ "5a9427658b0beebeb697bc39"

const updateResponse = await comments.updateOne(
{ _id: ObjectId(commentId), email: userEmail },
{ $set: { text, date } }
Test result - FAILED:
● Create/Update Comments › Can update a comment

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

Expected: 1
Received: undefined

Wasted whole day to find the issue but didn’t succeeded.
Could you please help me to find the problem?
Why I’m getting different _id in addComment result?
Thank you in advance!

1 Like

Something is not quite right, your code seems valid (not following best practice but valid, best practice is to always wrap your fields with quotes - at least to my knowledge), and still you are getting both of your tests to fail… Are you updating the correct file, try maybe to put some complete nonsense and see if your output changes… try to log your object before inserting it with console.log, it is odd indeed.

Some people in previous iteration of this course had similar problem and the root cause was that the comment were not sorted correct in getMovie().


It totally makes sense, now when I think of it I think I did saw some comments about how to silence some tests etc., not sorted comments seems like the most plausible explanation for tests to fail in this case.

Thanks for the hint!
The problem was in comments sort - I’ve added ‘$sort’: { ‘date’: -1 } to the pipeline and successfully passed test.

1 Like

I too stuck with the same problem. Struggled with this error for 2 days. Finally, Your comment helped me to solve it. Thanks for posting your solution.

1 Like

SOLVED: Create/Update Comments

I am having this issue too, but I cannot figure out why.

  • Movies are sorted by date with
{$sort: {date: -1}}
  • I am able to create and update comments through the UI after I log in with a user.

The image below is a screenshot of console.log of [commentDoc] and the [RESULT] of the insertOne ops, insertedCount, and insertedId.



Same for me, the requirements needs to be updated because neither the description of the problem nor the comments in the code says something about the comments needs to be in certain order

Are you sure the $sort stage is after the $match stage in the $lookup?
The structure should be correct for the sort to work.

Yes, the problem was that the movie_id had the wrong type.
Please refer to the link next to SOLVED in my original post.


Unit tests for both create/update and delete comments working but the UI is showing an error although my getcomments is working on both ends. CMD is also not shoiwng any error so I can debug. Not able to complete my assignment because of this.
can someone help? its kind of urgent!

Hi @Monika_Aggarwal_61091,

Please share the code in the message I have sent.



PFA the code. Can you please help me to improve my score since my code is working on the local machine and even cmd is not giving any error

(Attachment Update_Delete_comment_code.txt is missing)


PFA the code. Can you please help me to improve my score since my code is working on the local machine and even cmd is not giving any error

Can you please have a look at it @kanikasingla

Looking into it.


Hi @Monika_Aggarwal_61091,

We did not want the functionality to use upsert. We wanted it to throw an error in case it is not user’s comment.

And this is NodeJS forum but thats okay. Sorry couldn’t reach you on time. I saw you have completed the course now.

If you are still interested, you can try replacing the code from detailed answer and check if it is able to pass. If not, I would love to know more about the code.