Update and delete Comments

Both update and delete methods are returning failed.

But I think it is correct.

const updateResponse = await comments.updateOne(
{ email: userEmail,
_id: new ObjectId(commentId)},
{ $set: { text, date } },

const deleteResponse = await comments.deleteOne({
_id: ObjectId(commentId),

Any idea why it is happening?

your $set doesn’t specify which field you want the text/date to be updated.

I have $set: { “text”: text, “date”: date } on mine.

Also I just realized that you have to make sure you have the $sort included in the pipeline in the getMovieById method. If you don’t have that, the update/delete doesn’t work properly. Good luck!

In JavaScript when you have variables like text and date,

{ text , date }

is equivalent to

{ “text” : text , “date” : date }.

See https://ariya.io/2013/02/es6-and-object-literal-property-value-shorthand