del siguiente esquema,
¿Cómo elimino un comentario de respuesta específico?
const Schemaa = mongoose.Schema({ questionBody: String, Comment:[{ commentBody: String, }], answer: [{ answerBody: String, Comment:[{ commentBody:String, /// i want to delete one specific comment having a unique }] /// 'Object _id. }] }) export default mongoose.model("Questions", Schemaa)
Utilicé el siguiente código para agregar un comentario en la sección de respuestas y funcionó bien...
const updatedQuestion = await Schemaa.updateOne( { 'answer._id' : answerId}, /// I passed that specific answer's _id { $push: { /// as answerId "answer.$.Comment": { commentBody} } })
Saludos.
detectó el error, está funcionando con esto ahora ...
await Questions.updateOne( { 'answer._id': answerId},{ $pull:{ 'answer.$.Comment' : { '_id' :commentId} } } )