Connecting to MongoDB database on mLab fails authentication
Asked Answered
N

9

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?

Nolanolan answered 18/3, 2016 at 10:49 Comment(1)
I think you should consider redefine the username and its password first of all.Beating
S
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:[email protected]:12345/db

Scraperboard answered 22/3, 2016 at 23:56 Comment(2)
For windows users, the command is: heroku config:get MONGODB_URIHattiehatton
heroku config:get MONGODB_URI for any system actually (Mac, Linux and Windows) is the cleaner wayOmidyar
D
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!

Debutant answered 23/3, 2016 at 15:14 Comment(4)
But is there a solution?Southport
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 :)Debutant
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!Levenson
my solution was install mongo 3.2Culver
P
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

Pedagogics answered 17/9, 2016 at 4:18 Comment(0)
L
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:[email protected]:47124/heroku_1ksph3jj

Lionel answered 4/5, 2016 at 15:56 Comment(2)
Thanks, I just put those there to show that the user and password were placeholders. I removed them before trying to connect.Nolanolan
this is the correct answer. seriously thank you. no clue why everyone else talking about versions. thank you!Mccullough
V
3

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

Victoir answered 9/6, 2016 at 9:18 Comment(1)
Thats it. Thanks for the advice.Disconnect
A
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.

Accepted answered 22/1, 2017 at 20:17 Comment(1)
I also had tried a password using an @, and the connection failed. This is still an issue!Schoolfellow
N
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.

Nolanolan answered 18/3, 2016 at 14:37 Comment(0)
V
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:[email protected]:63295/heroku_user

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

Voussoir answered 14/3, 2019 at 15:0 Comment(0)
S
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

Shiite answered 16/9, 2017 at 16:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.