freeCodeCamp Challenge Guide: Delete Many Documents with model.remove()

Delete Many Documents with model.remove()

Relevant Links


Hint 1

You just need a condition, and a callback with error and response .


Solution 1 (Click to Show/Hide)
const removeManyPeople = (done) => {
  const nameToRemove = "Mary";
  Person.remove({name: nameToRemove}, (err, response) => {
    if(err) return console.log(err);
    done(null, response);

Code Explanation

  • remove() sends a remove command to MongoDB to remove all matched documents. In this case, all documents with a name of Mary are removed.
  • The response is a JSON object containing properties such as deletedCount - containing the number of documents removed from the collection.

Relevant Links

1 Like