I need help updating a specific comment within a parent object in my database.
const QuestionSchema = mongoose.Schema({ //_id1
...
...
comment: [{ //_id2
commentBody: String,
...
...
}]
}]
The schema above shows the structure, and I am trying to update the commentBody of a particular field within the "comment" object. The parent question's ID is represented by <_id1> and the comment's ID is represented by <_id2>.
I have attempted to do this as a beginner but it is not working.
Please help me identify any syntactic or logical errors in this code.
const updatedQuestioncomment = await Questions.findByIdAndUpdate({ "_id": _id1 }, { "comment._id": id2 }, { $set: { 'comment': [{ 'commentBody': commentBody }] } });
Your assistance is much appreciated!