10
votes

I have a very simple Mlab account and I'm trying to connect via command line with this command:

mongo server_name.mlab.com:port/inventory -u <dbuser> -p <dbpassword> 

but I keep running into this problem:

2016-05-26T15:41:18.195+0200 Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } at src/mongo/shell/db.js:1210 exception: login failed

How do I get rid of this and how can I connect to mlab easily?

4

4 Answers

15
votes

I think that you're using your mLab credentials. You must set a DB User at the User Tab like this:

Add Database user

14
votes

If (like me) you were positive that you were using the correct credentials for the database and for some reason you were still getting the Error: 18 { ok: 0.0, errmsg: "auth failed", code: 18 } thing, here's what I did.

First check your version of mongo.

$ mongo --version

If it is less than 3.x.x congratulations, you've found the problem.

For my linux users out there, go here to update your mongo. After that your connection should succeed!

8
votes

I had the same problem, if your username and password is correct then the issue connecting is your firewall blocking certain ports.

Use a different internet connection and it will work.

5
votes

Make sure to create a user with a different username and password than your mLab account.

In addition to Rafa's answer, if you choose to create a user with the same username and password as your mLab account (which is what I did to save myself from remembering another username and password), you will also not be able to connect.

Upon deleting that user and creating a new one, I was immediately able to connect.