0 votes
1 view
in SQL by (28.1k points)

I have a database wrapper class that establishes a connection to some MongoDB instance:

async connect(connectionString: string): Promise<void> { 

this.client = await MongoClient.connect(connectionString) 

this.db = this.client.db() 


This gave me a warning:

(node:4833) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.

The connect() method accepts a MongoClientOptions instance as second argument. But it doesn't have a property called useNewUrlParser. I also tried to set those property in the connection string like this: mongodb:// but it has no effect on those warning.

So how can I set useNewUrlParser to remove those warning? This is important to me since the script should run as cron and those warnings result in trash-mail spam.

I'm using mongodb driver in version 3.1.0-beta4 with corresponding @types/mongodb package in 3.0.18. Both of them are the latest available using npm install.


Using an older version of MongoDB driver:

"mongodb": "~3.0.8", "@types/mongodb": "~3.0.18"

1 Answer

0 votes
by (68.3k points)

You can see the below-highlighted code to mongoose connection solved the warning for mongoose driver

mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true });