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

302
Views
How to delete nested object from nested object by name

I have mongodb collection like that enter image description here

I want to delete object with its Team-name and player-name in mongoose . This is the how I tried.

router.post("/deletePlayer", auth, (req, res) => {
  const playerName = req.body.playerName; //'ahmet '
  const teamName = req.body.teamName;//'Team A'
  Item.findOneAndRemove(
    { name: { $players.name: playerName } },
    function (err, docs) {
      if (err) {
        console.log(err);
      } else {
        console.log("Removed User : ", docs);
      }
    }
  );
});

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

use update with $pull

db.collection.update({
  name: "Team A"
},
{
  $pull: {
    player: {
      name: "c"
    }
  }
})

mongoplayground

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