The error I was receiving was :
(node:998) [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:4919:18
at processTicksAndRejections (internal/process/task_queues.js:79:11)
So I assumed that remove() and deleteMany() were returning an object instead of a string. So I changed my code to :
const removeManyPeople = (done) => {
const nameToRemove = "Mary";
Person.deleteMany({name: nameToRemove}, (err, response) => {
if(err) return console.error(err);
console.log(JSON.stringify(response))
done(null, JSON.stringify(response));
})
};
which returned successful delete POST without error. However, the test still FAILS and I cannot pass the test. How can I fix this?:
Your app is listening on port 3000
OPTIONS
POST
(node:1069) [MONGODB DRIVER] Warning: collection.remove is deprecated. Use deleteOne, deleteMany, or bulkWrite instead.
{"deletedCount":2}
Your project link(s)
solution: https://replit.com/@catherineyang2/boilerplate-mongomongoose
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Challenge: Delete Many Documents with model.remove()
Link to the challenge: