I have mongodb collection like that
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);
}
}
);
});
CodePudding user response:
use update
with $pull
db.collection.update({
name: "Team A"
},
{
$pull: {
player: {
name: "c"
}
}
})