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

185
Views
Why is my Update fails to address a field even though it finds the right document?

here is an example of a JSON file of a document

{
  _id: new ObjectId("6212fc135188d701253762a2"),
  title: 'How do i make a lemon?',
  text: '<p>please im confused?????</p>',
  authorUsername: 'SweetWhite',
  dateCreated: 2022-02-21T02:42:27.837Z,
  answers: [
    {
      authorUsername: 'SweetWhite',
      text: '<p>YOU GOTTA DO THE RAIN DANCE YEAH AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA</p>',
      date: 2022-02-21T02:42:42.785Z,
      replies: [],
      likes: [Array],
      dislikes: [Array],
      reports: [Array]
    }
  ],
  likes: [ 0 ],
  dislikes: [ 0 ],
  tag: 'History',
  views: [ 1, 'SweetWhite' ],
  reports: [ 'SweetWhite' ],
  checked: false,
  reportsNested: [ { username: 'SweetWhite', answerIndex: 0 } ],
  __v: 0
}

and here is my query for the update with the router:

router.post('/reportsNested', 
  body('nestedReportObj'),
  body('questionTitle'),

  function(req,res,next){
  console.log(req.body.questionTitle);
  console.log(req.body.nestedReportObj) 
  Question.updateOne({title: req.body.questionTitle},
    {$pull: {reportsNested: req.body.nestedReportObj}},
    function(err, result){
      if(err) {return next(err)}
      console.log(result)  
    }
  )  
  res.redirect(req.get('referer'))
})

the console logs print out

How do i make a lemon?
{"username":"SweetWhite","answerIndex":0}
{
  acknowledged: true,
  modifiedCount: 0,
  upsertedId: null,
  upsertedCount: 0,
  matchedCount: 1
}

the first two console logs print okay values, they find the right document using the title and also they print the right value we want to pull.

from the last log it seems it found the right document, but did not update anything, why is that? in my router I am pulling a value from the reportsNested, which seems to be a field in the JSON file, why is it not pulling anything then? what am I doing wrong?

Thanks!

about 4 years ago · Juan Pablo Isaza
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!