Can't Connect to Mlab
Asked Answered
B

4

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?

Bieber answered 26/5, 2016 at 13:42 Comment(0)
D
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!

Dink answered 8/2, 2017 at 16:19 Comment(1)
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.Significancy
B
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

Batho answered 3/8, 2016 at 20:59 Comment(2)
that was the problem for me .. now it works correctlyLexicostatistics
thanks!. my problem was that any functions didn;t workMciver
D
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!

Dink answered 8/2, 2017 at 16:19 Comment(1)
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.Significancy
S
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.

Stranger answered 25/7, 2016 at 6:39 Comment(2)
uh. This Solved for me.Thanks a lotScrutator
How do you which ports need to be used so you can know which ones to unblock?Hoarhound
S
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.

Significancy answered 3/8, 2017 at 5:30 Comment(1)
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.Zeldazelde

© 2022 - 2024 — McMap. All rights reserved.