Listed solution doesn't work for mongodb

Tell us what’s happening:
The listed solution that is copied and pasted isn’t even working. At this point I’m starting to think it’s not my fault.

I’m getting:
(node:2611) [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 ()
at /home/runner/boilerplate-mongomongoose/server.js:346:29
at /home/runner/boilerplate-mongomongoose/node_modules/mongoose/lib/model.js:4994:18

Your project link(s)

solution: boilerplate-mongomongoose - Replit

Your browser information:

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

Challenge: Delete Many Documents with model.remove()

Link to the challenge:

The error is kinda self-explanatory, collection.remove was removed from the mongo-db driver since v5 I think in favour of deleteOne/Many.

I can see from Mongoose documentation that it was deprecated in mongoose v6 as well, as it should be:
https://mongoosejs.com/docs/deprecations.html#remove

But it’s not deprecated in v5, which is the one FCC is using:
(first lesson of the mongoose curriculum)

Add mongodb@~3.6.0 and mongoose@~5.4.0 to the project’s package.json .

So I think you should run the exact version of both mongo and mongoose in order to avoid issues, at least for this challenge sake.

I think once you will work on your own API project you can use the latest versions of both :sparkles:

Hope this helps.

I feel silly. I know I put ~5.4.0 in the package.json but somehow it updated to ^6.x.x

For anyone who runs in to this problem, you have to put mongoose first and mongodb second in the package.json at least for replit. It autoupdated the mongoose version when I put mongodb as a dependency first.

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