Getting [DEP0170] DeprecationWarning when connecting MongoDB Atlas with node:lts-slim (Node.js 20.9.0)

[DEP0170] DeprecationWarning: The URL mongodb://<USERNAME>:<PASSWORD>@ac-4hlp44x-shard-00-01.nqjamzn.mongodb.net:27017,ac-4hlp44x-shard-00-02.nqjamzn.mongodb.net:27017,ac-4hlp44x-shard-00-00.nqjamzn.mongodb.net:27017/<DATABASE>?authSource=admin&replicaSet=atlas-g8a2vr-shard-0&retryWrites=true&w=majority&ssl=true is invalid. Future versions of Node.js will throw an error.
2 Likes

Hey have you fixed this problem? Currently I am facing the similar problem

1 Like

Hi I think I read something related Receive DEP0170 when connecting MongoDB Atlas with Node.js 20.3.1 - Stack Overflow, I think they’re saying it’s because of the numerous :, making node thinking it’s port numbers.

Facing the same issue,is there any solution for this?

I have the same issue!

I keep getting the same erro while trying to deploy my node js project on render.com

1 Like

Which version of the Node.js Driver are you using? Ignore this, we found the info we needed (see below)

Note that after a bit of digging we’ve filed NODE-5802 for this issue. For anyone watching this thread the issue only affects 3.x of the driver (and any version of Mongoose that pins a 3.x version of the driver).

Upgrading to 4.x+ will address this warning.

Never mind. I was using a mongodb driver of version 2.x. I upgraded to 3.x and the issue was resolved. Thanks for the response.

I encountered the same issue and resolved it it this way :
I uninstalled the mongoose and mongodb packages.
Afterward, I installed the latest version of mongoose using this command:

npm install mongoose@latest

Upon encountering this error:
“connection error: MongoParseError: options usecreateindex, usefindandmodify are not supported at parseOptions”.

I updated my mongoose connection method. Now, it looks like this:

mongoose.connect(dbUrl);

As a result, everything is now working well.

1 Like

I wanted to add to the discussion for those who came to this thread after searching for a solution. I made the above updates to “mongoose” and was still getting the error message.

I forgot that I was also connecting using a MongoDB transport for Winston.

If you are using “winston-mongodb” don’t forget to add options:

winston.add(
  new winston.transports.MongoDB({
    db: 'mongodb://localhost/vidly',
    level: 'error',
    options: { useUnifiedTopology: true },
  })
);

I have a similar situation to yours:

winston.add(
  new winston.transports.MongoDB({
    level: 'info',
    db: process.env.DATABASE,
    collection: 'info_logs',
    options: {
      useUnifiedTopology: true,
    },
  })
);

But I had the error:
[DEP0170] DeprecationWarning: The URL mongodb://<USERNAME>:<PASSWORD>@ac-4hlp44x-shard-00-01.nqjamzn.mongodb.net:27017,ac-4hlp44x-shard-00-02.nqjamzn.mongodb.net:27017,ac-4hlp44x-shard-00-00.nqjamzn.mongodb.net:27017/<DATABASE>?authSource=admin&replicaSet=atlas-g8a2vr-shard-0&retryWrites=true&w=majority&ssl=true is invalid. Future versions of Node.js will throw an error.

Update to latest for Winston, MongoDb, Mongoose. Then run “npm ci” , this cleared everything up for me.

i had the same problem this is caused by old version of mongoose
just update mongoose and it well be solved
npm install mongoose@latest