I am trying to remove keywords with Nodejs and Express from a mongoose document that looks somewhat like this:
{
name: "Instagram",
description: "Image sharing website",
keywords: [{name:"Image", value: 1}, {name:"sharing", value: 1}, {name:"website"}, {name:"Instagram", value:5}, {name:"application", value: 2}]
}
Here is the part of my update query which seems to the problem (it does not delete the keywords properly if there are many keywords, though it has worked a couple of times with few keywords):
Model.findOne({_id:req.body.id}, function(err,doc){
for(var i = 0; i < doc.keywords.length; i++){
if(doc.keywords[i].value == 1){
doc.keywords.splice(doc.keywords[i], 1); //does nothing
doc.save()
console.log(doc.keywords[i]) //Shows the correct keywords to be deleted.
}
};
})