I'm trying to delete an object inside an array in my DB using the $pull
in Mongoose but does not work.
This is my attempt:
const listSchema = new Schema({
name: String,
items: []
});
const List = mongoose.model("list", listSchema);
const itemDeleted = req.body.checkbox;
//I get here the ID of the object inside the array
const itemListDeleted = req.body.listDeleted;
// Here the name of the object that contains the array
List.findOneAndUpdate({name:itemListDeleted},{$pull:{items:{_id: itemDeleted}}},function (err,foundList) {
if (foundList){
res.redirect("/"+ itemListDeleted);
} else {
console.log(err);
}
})
I searched for solutions and everybody recommends using $Pull
but in my case, it doesn't work. I log the const and all things appear to be right.
Do you have any suggestions?
Via Active questions tagged javascript - Stack Overflow https://ift.tt/YcnQmzt
Comments
Post a Comment