Saturday, 6 May 2017

mongoose finds but doesn't remove

I am finding any document that matches my condition and I want to remove those docs.

MyModle.find({writer: req.body.id}, function(err, docs){
                if (err){ return console.log(err)}
                if (!docs || !Array.isArray(docs) || docs.length === 0){
                    return console.log('no docs found')}
                docs.forEach( function (doc) {
                    doc.remove();
                    console.log("Removed book with ID ",doc._id, "by writer ", req.body.id);
                });
            });

My console is printing the message as if the document was removed, but it is still in the collection. What is wrong here?



via cplus

No comments:

Post a Comment