Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Current URL string parser is deprecated [duplicate]

when I run the code by "node app.js" command this error is showing

(node:2509) 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.

like image 913
Yusuf Delvi Avatar asked Jul 04 '18 03:07

Yusuf Delvi


People also ask

How do you use useNewUrlParser?

The useNewUrlParser Option 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 MongoDB Node.

What is useCreateIndex?

the useCreateIndex option ensures that you are using the new function calls. Reference: https://mongoosejs.com/docs/connections.html#options https://mongoosejs.com/docs/deprecations.html. Follow this answer to receive notifications.

How do you use useUnifiedTopology true?

How to use it. The unified topology is available now behind the useUnifiedTopology feature flag. You can opt in to using it by passing the option to your MongoClient constructor: const client = MongoClient('mongodb://localhost:27017', { useUnifiedTopology: true });


2 Answers

You need to pass { useNewUrlParser: true } option to mongoose.connect() method. Your code should look similar to the snippet below.

mongoose.connect('mongodb://user:[email protected]:27017/dbname', { useNewUrlParser: true })
like image 135
Nyambati Thomas Avatar answered Sep 24 '22 20:09

Nyambati Thomas


to avoid this problem use this

MongoClient.connect('mongodb://user:[email protected]:port/dbname', { useNewUrlParser: true })
like image 5
AAshish jha Avatar answered Sep 22 '22 20:09

AAshish jha