2

I'm trying to connect mongodb from mlabs. I've inserted the following code:

Mongoose.connect('mongodb://<dhan004>:<password1>@ds163402.mlab.com:63402/projecttwist', {useNewUrlParser: true }); 

It then gave me this error:

(node:32032) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): MongoError: Authentication failed.

Can anyone explain why I'm getting this error?

Addison
  • 7,322
  • 2
  • 39
  • 55
dhan004
  • 45
  • 8
  • The error indicates that it failed on authentication, so check the username and password portion of your connection string, which usually goes by: `protocol://username:password@host:port/path`, in this case protocol is `mongodb`, `host:port` parts you should double check too, and `path` part in this case point to the DB. Double check all parts based on this and try again. – woozyking Sep 20 '18 at 04:19
  • appreciate the help. Thank you! – dhan004 Sep 20 '18 at 06:51
  • Possible duplicate of [Unhandled promise rejection: Error: URL malformed, cannot be parsed](https://stackoverflow.com/questions/50590080/unhandled-promise-rejection-error-url-malformed-cannot-be-parsed) – Ashh Sep 20 '18 at 08:52

1 Answers1

2

Just remove the brackets(both < and the >) from the username and password section.

For username should use: dhan004

And for the password you should use: password1

So your final db address should be:

Mongoose.connect('mongodb://dhan004:password1@ds163402.mlab.com:63402/projecttwist', {useNewUrlParser: true });
Shams Nahid
  • 6,239
  • 8
  • 28
  • 39