Reputation: 137
I am connecting to my MongoDB with node.js. The server connects to the database, but I get an annoying error message.
This is the error:
(node:9252) 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.
here is my code which is located in a separate file that : server.js
:
module.exports = {
mongoURI: 'mongodb://127.0.0.1:27017/shoppinglist'
}
I wish to connect to mongodb without having any errors. I am running version 3.4.18
Upvotes: 0
Views: 687
Reputation: 61
First of all, it is not an error, it is just a warning and it would not bother the functioning. If you don't want to see this warning, I recommend two methods.
First, by using { useNewUrlParser: true }
you can avoid this warning message.
MongoClient.connect('mongodb://127.0.0.1:27017/shoppinglist', { useNewUrlParser: true });
Second, most probably you are using mongo version >= 3.1.0 and to avoid this warning you can use 3.0.x releases.
"dependencies": { "mongodb": "~3.0.8" }
Upvotes: 1
Reputation: 5202
It's not an error it's a warning (related to mongo version):
Mongo >= 3.1.0
MongoClient.connect("mongodb://localhost:27017/shoppinglist", { useNewUrlParser: true })
Upvotes: 0
Reputation: 84
The warning message suggestion should fix the problem, you just need to add:
{ useNewUrlParser: true }
to your MongoClient.connect to be like this:
MongoClient.connect('mongodb://127.0.0.1:27017/shoppinglist', { useNewUrlParser: true });
Upvotes: 0