MongoDB and Mongoose - Delete Many Documents with model.remove()

Tell us what’s happening:

I have been struggling with this test, everything seems fine but the test does not pass, it keeps giving me this error ‘Model.deleteMany() no longer accepts a callback’ .

Person.remove = Person.deleteMany;

const removeManyPeople = (done) => {
  const nameToRemove = "Mary";
  Person.deleteMany({ name: nameToRemove })
    .then((result) => done(null, result))
    .catch((err) => done(err));
};


###Your project link(s)

https://3000-freecodecam-boilerplate-qdt75dvqzfc.ws-eu118.gitpod.io

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36

Challenge Information:

MongoDB and Mongoose - Delete Many Documents with model.remove()

You have posted a link to the boiler plate, this is the same if I just opened it up myself. There needs to be a snapshot or a live URL.

How Can I Share My Workspace To Get Help?

You can create a snapshot of your workspace to generate a sharable URL you can use on our forum or our Discord, for example.

However, your snapshot WILL include your .env file, with any secret values you have written. Before generating a snapshot, you should move the secrets from the .env file to your user variables, which are not shared in your snapshot.

Modify the removeManyPeople function to delete all the people whose name is within the variable nameToRemove , using Model.remove()

The instructions ask you to use Model.remove(), not Model.deleteMany().

Do not update the Mongoose dependency. Use the version that is in the starting boilerplate.

1 Like

When I use Model.remove(), I get this error ‘[Error: Person.remove is not a function]’ and when I look up why I get this error, it says Mongoose v7+ no longer recognizes Model.remove() as a method and that I should instead use Model.deleteMany().

1 Like

Can I share the code like this instead, Github repo link

As @lasjorg said, it appears you installed a newer version of Mongoose rather than using versions of the dependencies in package.json. For that, you would need to delete your existing node_modules folder and run ‘npm install’ from the terminal. (I did this in VS Code on my local system.)

Yes, this is the correct way to post your repo. However this is what happens when I try to check the code with that link Remember to submit the Live App URL.

an url to a live app is needed for the tests to run

what link are you submitting for the live app url?

1 Like

I ended up restarting the whole project, and I saw where my mistake was now. The test passed. Thank you all, I appreciate the assistance. :slightly_smiling_face: