Ticket: Create/ Update/ Delete comments

I m stuck on the Update and Delete comments ticket. I believe my code is correct and I am passing 2/3 tests, however, Update is failing.


and the code is:


and for Delete:

I’ve tried all types of combinations including restarting the server. I need some advice, perhaps I can’t see something obvious. I also tried upsert.

Hello @Kevin_Turney,

I believe the updateComment allows the update only for the user who created that comment - and not for other users.

Yes, that is why the query specifies the specific _id and the user’s email. When I console.log(commentId, userEmail), and then query in Compass, no results are returned.

Try the query comments.findOne( { _id: ObjectId(commentId), email: userEmail } ) instead of the update and console.log the result.

I received “null ------- line 80”

@Kevin_Turney, null result means the query did not find any matching document (that is the reason the update failed). Note that findOne method returns a document or a null.

Respectfully, I realize that. What is the solution? should I manually insert this document in Compass and then run the test?

I don’t know if that is the correct procedure to get the test to pass.

Have you looked into the test script for the create-update-delete comments (it is one JS file)? It will have details of how the test is run along with the data used.

Also, note that if you are running the test again, make sure the previous data created by the test is cleared (sometimes it can be a problem) in the database / collection.

I have been running the tests over and over, how do I clear the data?

See these related posts are helpful: