0

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

2
  • Are you using mongoose or mongodb as your connector node module? Commented Aug 9, 2019 at 9:43
  • i am using mongoose Commented Aug 9, 2019 at 10:16

3 Answers 3

1

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"
}
Sign up to request clarification or add additional context in comments.

Comments

0

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 });

1 Comment

I get an error message saying MongoClient not defined please write down the full code i need to write.
0

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 })

2 Comments

it doesn't work....look at my code again and tell me how i should write it exactly
Can you share with me the file where you use mongoURI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.