• Empleos
  • Sobre nosotros
  • profesionales
    • Inicio
    • Empleos
    • Cursos y retos
  • empresas
    • Inicio
    • Publicar vacante
    • Nuestro proceso
    • Precios
    • Evaluaciones
    • Nómina
    • Blog
    • Comercial
    • Calculadora de salario

0

176
Vistas
$pull data from a double nested schema

from the below schema ,

how do i delete out one specific answer comment ??


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)

I used the below code, to Add a comment in answers section and it worked fine...


const updatedQuestion = await Schemaa.updateOne(
            { 'answer._id' : answerId},              /// I passed that specific answer's _id   
            { $push: {                               ///  as answerId
           "answer.$.Comment": { 
             commentBody}
            } 
           })

regards.

about 3 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

caught the error, its working with this now...


await Questions.updateOne(
            { 'answer._id': answerId},{
                $pull:{
                    'answer.$.Comment' : { '_id' :commentId}
                }
            }
        )

about 3 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recomiéndame algunas ofertas
Necesito ayuda