Im trying to update a certain property in my MongoDb.
This is the structure of the document:
"_id" : ObjectId("57e2645e11c979157400046e"),
"id" : 1651570992420,
"creator" : "nameHere",
"title" : "titleHere,
"content" : "contenthere",
"comments" : [
{
"id" : 1651733114268
"comment" : "commenthere"
"user": "userHere"
"timestamp": timeStampHere
},
{
"id" : 1651733114268
"comment" : "commenthere"
"user": "userHere"
"timestamp": timeStampHere
}
]
Now im trying to change the comment property of the comments array for a certain id in comments. I'm using the following method to update the comment property:
async deleteComment(commentId: number, threadId: number): Promise<void> {
try {
threadModel.updateOne(
{ id: threadId, "comments.id": commentId },
{ $set: { "comments.$.comment": "deleted" } }
);
} catch (e: any) {
console.log(e);
}
}
What I want to do is to simulate that a comment has been deleted by changeing the comment propery to the string "deleted".
However, the document doesnt get updated and I don't get an error message and I'm not sure how one would go about to debug an update to MongoDB. I can add these comments to the mongodatabse using a similar strategy but updateing doesn's seem to work. Any suggestions where I might have gone wrong?
Im trying to do something similar to this post: here