Unable to delete documents - mongoDB

I’m unable to delete many documents and I’m not able to figure out where I’m going wrong. Can anyone please point out where I’m wrong?
Thank you.

Here is what I have in my code

const removeManyPeople = (done) => {
  const nameToRemove = "Mary";
  Person.deleteMany({name: nameToRemove},(err,res)=>{
    if(err) return console.log(err)
    done(null,res)
  })
};

The error I’m getting:

(node:851) [MONGODB DRIVER] Warning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
SyntaxError: Unexpected token o in JSON at position 1
    at JSON.parse (<anonymous>)
    at /home/runner/boilerplate-mongomongoose/server.js:346:29
    at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/model.js:4931:18
    at processTicksAndRejections (internal/process/task_queues.js:79:11)

Here is a link to my repl.it
https://replit.com/@SandeepGumaste/boilerplate-mongomongoose#myApp.js

Your browser information:

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

Challenge: Chain Search Query Helpers to Narrow Search Results

Link to the challenge:

Downgrade your mongoose version to the one you were asked to use in the starting challenge.

Thank you very much, just did that. Also can I please ask why is it not working with Person.deleteMany() ?. or FCC test suite is not able to detect it?

After you use the correct version of mongoose it should pass the test.

I can’t remember off the top of my head what the change is to mongoose that is making it fail with newer versions.

1 Like

Ok. Thank you very much.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.