Current URL string parser is deprecated [duplicate]
Asked Answered
D

3

18

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.

Dupin answered 4/7, 2018 at 3:56 Comment(1)
it's a warning. Also, it gives you the information to fix it. I'm not sure what you are askingBuonomo
W
32

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 })
Wallasey answered 5/7, 2018 at 2:7 Comment(2)
when I make this it gives me error <code> UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): [object Object] (node:7) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. </code> even I didn't mention anything related to promiseRabblerouser
@Rabblerouser I am getting the same error when passing the { useNewUrlParser: true } in as the second param between url and callbackGorga
D
5

to avoid this problem use this

MongoClient.connect('mongodb://user:[email protected]:port/dbname', { useNewUrlParser: true })
Droppings answered 9/7, 2018 at 6:56 Comment(1)
in which file should I use this snippet?Allx
C
0

For those having this message "DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. even I didn't mention anything related to promise"

I pasted the code the error gets fixed with in the following link. https://mcmap.net/q/669844/-connection-to-mongodb

Cassycast answered 22/9, 2018 at 17:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.