About mongo’s useNewUrlParser warning

Recently I got this warning when trying to create a new MongoDB application

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

Turns out I’m the first few to use the new MongoDB driver released on npm over the weekend.

The new URL parser has no big changes (yet). Currently it only forces you to put the port into the URL

You can resolve the above warning by changing from

MongoClient.connect("mongodb://localhost:27017")

to

MongoClient.connect("mongodb://localhost:27017", { useNewUrlParser: true })

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.