Deprecation error mongodb and mongoose

I followed the instructions on how to install and set up mongoose, I included the MONGO_URI in the secrets tab with the value:

mongodb+srv://user_khal45:<password>@cluster0.mrqu5ly.mongodb.net/?retryWrites=true&w=majority

replacing password with my password as instructed in this tutorial MongoDB Atlas Tutorial – How to Get Started . But I’m getting a deprecation warning:

(node:370) [DEP0170] DeprecationWarning: The URL mongodb://user_khal45:@ac-tu5n7sf-shard-00-00.mrqu5ly.mongodb.net:27017,ac-tu5n7sf-shard-00-01.mrqu5ly.mongodb.net:27017,ac-tu5n7sf-shard-00-02.mrqu5ly.mongodb.net:27017/?authSource=admin&replicaSet=atlas-cypibf-shard-0&retryWrites=true&w=majority&ssl=true is invalid. Future versions of Node.js will throw an error.
(Use node --trace-deprecation ... to show where the warning was created).

I replaced password with my actual password in this post I did not actually write password there. The images attached are the error message and my secrets file.


That doesn’t look like a correct connection string. Make sure it follows the example format from the article.

mongodb+srv://<username>:<password>@<cluster-name>.prx1c.mongodb.net/<db-name>?retryWrites=true&w=majority

After you click the “Connect” button pick the “Drivers” option and do not add anything else to the connection string.

There is no dbname in the connection string. I copied the string and only replaced the password with my own password.


I also tried including a dbname before the ? but it gave me the same error.
Here is the raw secrets editor with the dbname:

Without the dbname:

Both gave me the same error.

Edit: If you are reading this because you are completing the MongoDB and Mongoose freeCodeCamp challenge - read this post.


Looks like it is a bug with the version of the driver and Node 20. Updating mongoose should fix it.

Open the Shell tab and run npm i mongoose@latest

You can also remove the options object from the connect call as both those options are now deprecated.


BTW, it looks like Gitpod is now the preferred option and not Replit. The challenge instructions have been updated accordingly. But I’m guessing it still works fine with Replit.

If you need help with your code we have to see it. Post a link to your Replit or a GitHub repo.

You should not use the sample.env file, it should just be named .env and on Replit you use the secrets, not an env file.

Thank you I’ve fixed it, I got a dev to help me thank you very much for your help.

Sorry if it’s out of pocket, but running " npm i mongoose@latest" would work too? I tried it in the terminal but it didn’t work. I assume there’s some difference, because when I saw video examples they usd npm start, but I would have to write npm run start for the same process.
Sorry, don’t english all that well.

Installing/updating dependencies and running the start script are two different things.

Running npm i someDependency@latest will update the dependency. You can check the version in the package.json file.

npm start and npm run start is the same command. There are a few run commands that do not need run as part of the command. It runs the start script found in package.json under the scripts section.

it seems to violate this condition on the project
``1. “mongoose version ^5.11.15” dependency should be in package.json`

You should be able to ignore the deprecation warning.

Not sure for how long, at some point you might have to downgrade the Node.js version. I would assume it will continue to work with V20 and below.

Upgrading to mongoose latest (^8.8.4 ) did fix the deprecation warning for me and I’m using node v21.7.1.

However, when completing the ‘Create Many Records’ challenge I get the error: Person.remove is not a function. Is this a mongoose version issue for the server.js file?

The mongoose API has changed and will continue to change with each major version.

Each version has migration docs.

In some cases, you might be able to update the version and use the new methods and still pass the challenge tests. But that is far from guaranteed.


For the fCC challenges, you should stay with the dependencies in the boilerplate to avoid issues. So far, there are no breaking changes that strictly requires the boilerplate to be updated. We could update the dependencies and methods taught, but that may be more work than it is worth if the tests need to be updated as well. Pretty sure this part of the curriculum is going to be legacy soon enough.

As long as it is just a deprecation warning, it doesn’t affect anything. It is just warning you that future versions of Node will start to throw, but as long as the version of Node you are using isn’t throwing, you can just ignore the warning and use the boilerplate dependencies. I just tested it with the current Node LTS version (22.12.0 as of writing) and it still is just a deprecation warning.

The initial posts I made about this issue (Node/Mongoose/MongoDB driver) wasn’t with the challenge in mind. I hadn’t connected it to an fCC challenge initially.


TL;DR stay with the boilerplate dependencies and ignore the deprecation warning.

1 Like