Delete Many Documents with model.remove()

I’ve been really struggling with the MongoDB and Mongoose Challenges and have finally gotten all but one to work.

My code is:


const removeManyPeople = function(done) {
  const nameToRemove = "Mary";
  Person.deleteMany({name: nameToRemove}, function(err, data) {
    if(err) return done(err);
    return done(null, data);
  });
};

I also changed the server.js file at line 258 to be:

Person.deleteMany({}, function(err) {

because I continued to get this error: “(node:1285) DeprecationWarning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.”

I feel like I have tried everything under the sun at this point and continue to get the same response, namely:

OPTIONS

POST

[object Object]

I’m not sure what the [object Object] refers to, I assume the json file returned by the function? I am really new to this and am don’t even know where else to look for my problem at this point.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

Note: Backticks are not single quotes.

markdown_Forums

1 Like

I eventually got it to work. I moved on to some of the projects and then came back. For some reason the “People” collection in mongodb was not responding to any requests, so I deleted it (the collection) and when it regenerated everything worked fine.

Thank you for the suggestion. I did the same. For what it’s worth: I had changed the name from ‘Mary’ into another one. The test passed when I changed it back into the original ‘Mary’ and emptied the collection.

Karin