19

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.

Yusuf Delvi
  • 300
  • 1
  • 2
  • 6
  • it's a warning. Also, it gives you the information to fix it. I'm not sure what you are asking – njzk2 Jul 04 '18 at 03:58

3 Answers3

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:pw@host1.com:27017/dbname', { useNewUrlParser: true })
Nyambati Thomas
  • 346
  • 3
  • 4
  • 4
    when I make this it gives me error 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. even I didn't mention anything related to promise – palAlaa Jul 08 '18 at 08:55
  • @palAlaa I am getting the same error when passing the { useNewUrlParser: true } in as the second param between `url` and `callback` – Phillip Berger Jul 11 '18 at 19:47
5

to avoid this problem use this

MongoClient.connect('mongodb://user:password@sample.com:port/dbname', { useNewUrlParser: true })
Julian
  • 8,808
  • 8
  • 51
  • 90
AAshish jha
  • 952
  • 8
  • 6
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://stackoverflow.com/a/52459082/10399142

Mario Minondo
  • 105
  • 1
  • 5