27

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?

Blakes Seven
  • 49,422
  • 14
  • 129
  • 135
Adam Colvin
  • 751
  • 1
  • 6
  • 16

9 Answers9

64

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:example_pass@mlab.com:12345/db

Filip Cornelissen
  • 3,682
  • 3
  • 31
  • 41
Imjohsep
  • 900
  • 8
  • 8
11

As of March 2016, mLab.com only supports mongo 3.0+ (as per a conversation with support), because of their new onerous authentication requirements.

This was not on the website, but I hope it helps someone here!

lol
  • 3,910
  • 2
  • 37
  • 40
  • But is there a solution? – R Menke Mar 25 '16 at 11:36
  • 1
    My solution was to get on a fugly dev box I had somewhere else, download the mongo 3+ client (on centos 7 it's really easy) and not sully my day-to-day mac! Hope that helps :) – lol Mar 26 '16 at 06:37
  • It definitely helped, currently the mongo version on Ubuntu defaults PPA is 2.6, I'd never pass authentication even with correct credentials, thanks a ton for this! – Miguelgraz May 05 '16 at 16:26
  • 2
    my solution was install mongo 3.2 – David Hackro Jul 05 '16 at 14:17
7

There's a message to create a user for the specific database: A database user is required to connect to this database. To create one now, visit the 'Users' tab and click the 'Add database user' button

user3551863
  • 301
  • 3
  • 7
3

I'm so sorry that this may seem obvious but, you have to remove this characters <> for the migration to work

In your example would look like this: mongodb://dbuser:dbpassword@ds047124.mlab.com:47124/heroku_1ksph3jj

Leo Melo
  • 196
  • 5
  • Thanks, I just put those there to show that the user and password were placeholders. I removed them before trying to connect. – Adam Colvin May 04 '16 at 16:02
  • 1
    this is the correct answer. seriously thank you. no clue why everyone else talking about versions. thank you! – Ibdakine Jul 26 '16 at 17:53
3

Check your mongo client version. If it is in older major version (probably 2.x), update it to 3.x

kyasar
  • 439
  • 5
  • 7
3

For future visitors - don't use special characters in password .Even if you change the special character to ascii or unicode it wont work for mLab using mongoose.

Also don't use mLab credential , use db user credentials . I created a new user.

Eg. For me a password containing @ character was replaced with ascii value %40 in URI , which worked when using native mongodb driver. But on using mongoose, i was always getting Authentication Failed . I removed special characters and db was authenticated via mongoose.

Divyanshu Jimmy
  • 2,542
  • 5
  • 32
  • 48
  • 1
    I also had tried a password using an @, and the connection failed. This is still an issue! – jessi Feb 08 '18 at 05:46
2

It looks like it was the password that was incorrect, which I'm assuming was set up by Heroku's mLab add-on. There was no obvious way to reset this in the mLab UI, so in the end I created another database user (with a new username and password) and was able to connect with that just fine.

Adam Colvin
  • 751
  • 1
  • 6
  • 16
2

Just go to your Heroku dashboard and check your settings.

Under the name field there's a big button "Reveal Config Vars". Click it and you'll see a MONGODB_URI var with a uri to your db. It'll look something like this:

mongodb://heroku_user:PASSWORDyourLOOKINGfor@ds2238985.mlab.com:63295/heroku_user

Your password is right after the semicolon after the heroku user name.

insp_moore
  • 46
  • 3
1

I know I am too late, just for information. For getting the info of mLab account that got auto created when mLab addon got added to the application in your heroku account, try the below command.

heroku config:get MONGODB_URI

Ref: http://algebra.sci.csueastbay.edu/~grewe/CS6320/Mat/NodeJS/Heroku/Heroku_MLabMongoDB.html

Predhin
  • 51
  • 2