Saturday, 6 May 2017

mongoose find and save not updating the document

I am using mongoose to find and modify and save back to the collection. Here is what I have tried:

if(req.body.writer){
     MyModel.find({writer: req.body.oldname},function (err, data) {
                for(var i = 0; i < data.length; i++){
                    data[i].writer= req.body.newName;
                    data[i].save()                    
                }
            });
}

why is this not updating the document? where is the problem lying? thanks



via cplus

No comments:

Post a Comment