(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 :
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}
If you check the code at server.js line 346 it’s in an if statement
if (data.ok === undefined) {
The code expects an ok property and if it’s not present, it tries to parse the data as json.
The problem here is that data is already an object, it’s not a string. So string form of the data is [object Object] and the first o is causing the Unexpected token o in JSON at position 1 error.
I would suggest checking your versions for Mongoose and MongoDB. I recently had this issue and it’s being updated to show the correct versions in the curriculum.