• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

229
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);
      }
    }
  );
});

almost 3 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

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error