10

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?

blackbishop
  • 30,945
  • 11
  • 55
  • 76
xupv5
  • 239
  • 1
  • 2
  • 9

4 Answers4

15

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

Add Database user

Rafa Barragan
  • 602
  • 9
  • 24
14

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!

Henry Thomas
  • 428
  • 4
  • 9
  • FYI: When you create your `mLab` instance, you walk through some setup screens. One of them shows you exactly what version of `MongoDB` will be deployed. Try to ensure your local `MongoDB` installation is at least to that version in order to avoid any unintended errors. – Govind Rai Aug 03 '17 at 05:34
8

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.

n31l
  • 93
  • 1
  • 11
5

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.

Govind Rai
  • 14,406
  • 9
  • 72
  • 83
  • You, sir, are a gent! :) This problem has wrecked my buzz for ages and this was the only thing that fixed my problem for me. – PhillyStafford Mar 18 '18 at 23:21