Connecting to MongoDB database on mLab fails authentication

Adam Colvin picture Adam Colvin · Mar 18, 2016 · Viewed 20.5k times · Source

I have a Parse app, and I'm trying to migrate my app's database to a MongoDB instance on mLab.

I already have a fork of Parse Server set up on Heroku, and I'm using Heroku's mLab MongoDB add-on.

I have a database on mLab called heroku_1ksph3jj, and I should be able to connect to it with the following template:

mongodb://<dbuser>:<dbpassword>@ds047124.mlab.com:47124/heroku_1ksph3jj

However, each attempt returns:

Server returned error on SASL authentication step: Authentication failed.

I'm unsure what to replace <dbuser> and <dbpassword> with. I have a database user with the same name as my database: heroku_1ksph3jjz, so I used that. And I used the password for that user in place of <dbpassword>. Should I have used something else here?

Answer

Imjohsep picture Imjohsep · Mar 23, 2016

You can get the dbuser and dbpass with:

heroku config | grep MONGODB_URI

Grab the dbuser (example_user) and dbpass (example_pass) from the response:

MONGOLAB_URI: mongodb://example_user:[email protected]:12345/db