Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

204
Views
$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.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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


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

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!