How do I remove documents using Node.js Mongoose?

708    Asked by JanFerguson in Python , Asked on Jun 21, 2021
 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.


How mongoose delete the document?

Answered by Ayushi Khatri

 To remove documents using Node.js Mongoose without iterating, you can try

FBFriendModel.find({ id:333 }).remove( callback );
Or
FBFriendModel.find({ id:333 }).remove().exec();
The mongoose.model.find method returns a Query, which has a remove function.
This will work for mongoose delete document.

Your Answer

Interviews

Parent Categories