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.

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.