How do I remove documents using Node.js Mongoose?


Question

FBFriendModel.find({
    id: 333
}, function (err, docs) {
    docs.remove(); //Remove all the documents that match!
});

The above doesn't seem to work. The records are still there.

Can someone fix?

1
270
12/6/2017 10:46:04 AM

If you don't feel like iterating, try FBFriendModel.find({ id:333 }).remove( callback ); or FBFriendModel.find({ id:333 }).remove().exec();

mongoose.model.find returns a Query, which has a remove function.

466
2/13/2014 4:54:58 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon