Can't Connect to Mlab - mongodb

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?

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

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!

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.

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.

Related

cannot connect to mongo cluster - user is not allowed to do action [getLog] on [admin.]

I have created a user and added my IP to whitelist.
when trying to connect to a cluster through mongo shell, i am required to enter the following line: mongo "mongodb+srv://cluster0.****.mongodb.net/" --username --password
I have filled in credentials for username and password and replaced dbname with my database name(tried using non-existing one as well in case that was the problem). it connects to the shell, but then crashes with the following error:
Error while trying to show server startup warnings: user is not allowed to do action [getLog] on [admin.]
MongoDB Enterprise atlas-7cwf8s-shard-0:PRIMARY>
tried googling and youtubing the issue, but cannot find the match on how to fix it.
Many thanks
That message says that the shell is unable to show you server startup warnings. It's expected in Atlas environment.
Supposing that's your own cluster, then:
Check the user in Atlas > Database Access
Check the MongoDB Roles header in the table.
If it's not atlas Admin, you can't issue this command:
db.adminCommand({getLog:"startupWarnings"})
Or any admin command, which is issued or tested automatically in the connection, hence the error.
Edit MongoDB Roles to the highest privileges (atlas Admin)
But you can still work anyways.
If you're accessing someone else's cluster, then there isn't much to do.

Connecting to MongoLab shell (Azure cloud server)

So i spent quite a bit of time pulling my hair out trying to connect to our MongoLab account at work with a command line shell. I followed the instructions here but no for some reason mongoDB would always return: Error: 18 { code: 18, ok: 0.0, errmsg: "auth fails"}
My user name and password were coming from my database under the users collections which worked fine with my Node.js driver but wouldn't work with my shell.
The question is: where does one find the correct user name and password to connect to MongoLabs with the mongodb shell.
Turns out the user name and password to connect and authorize with the shell aren't found in MongoLabs but in Azure's portal.
Log into your Azure account, in the left column scroll down to Add-Ons and click.
You should see a MongoLab's. Go ahead and click on that.
From there click on Connection Info at the bottom of the window and it will display a string similar to this:
mongodb://username:password#ds012345.mongolab.com:56789/mongolab
go ahead and copy and paste that username and password into your shell with this command :
mongo ds012345.mongolab.com:56789/dbname -u dbuser -p dbpassword
NOTE: Your command will look different because you're using a different MongoLabs account.

Can't insert anything in MongoHQ database

I registered for a free sandbox database on MongoHQ.
As I am starting to use mongoDB I thought it would be a good idea to connect to MongoHQ database from the mongo console and run some commands before using it in any program.
I tried connecting to my database using:
Here testuser is my username and 123456 is my password (I know posting user id and passowrd on forums is bad, this user is temporary and will be deleted by me later).
mongo oceanic.mongohq.com:10076/tnh_data -u testUser -p 123456
and I got this:
MongoDB shell version: 2.4.9
connecting to: oceanic.mongohq.com:10076/tnh_data
Hoping that everything is running fine I tried running a few commands, but I am getting a not authorized error.
> show dbs
Sat Apr 19 22:00:18.090 listDatabases failed:{ "ok" : 0, "errmsg" : "unauthorized" } at src/mongo/shell/mongo.js:46
> use learn
switched to db learn
> db.collection0.insert({name: 'Harry', gender: 'Male'})
not authorized for insert on learn.collection0
Please help me what am I doing wrong ?
Just for the information. I created the users using the web interface on mongoHQ.
When using MongoHQ sandbox plans and logging in from the console, there are a couple of things that are at play:
When you connected, using the string above, you are already in your database (tnh_data)
You do not have admin-level access, so "show dbs" will not work in MongoDB console.
So, in MongoDB console, connect again using the same string you started with and, once connected, run this command: "show collections".
Also, without trying to switch to another database, run your insert again. It should work normally this time.
Hope this information is helpful!

Unable to connect to MongoLab "auth fails" error

I am new to mongo. Recently created an account in mongoLab.
I am trying to connect to the database using the below statement.
mongo ds039487.mongolab.com:39487/webbies -u <dbuser> -p <dbpassword>
Getting the below error
MongoDB shell version: 2.4.8
connecting to: ds039487.mongolab.com:39487/webbies
Wed Dec 11 22:30:16.686 Error: 18 { code: 18, ok: 0.0, errmsg: "auth fails" } at src/mongo/shell/db.js:228
exception: login failed
Note:
dbuser - is an User created in mongoLab
What is missing in this? Kindly advice.
Old thread, but just in case it helps anyone else: my problem was using shell version 2.4.9 to connect to mongo db version 3.0.7 (http://docs.mongolab.com/connecting/#mongo_shell).
Updating my shell sorted it (https://docs.mongodb.org/master/tutorial/install-mongodb-on-ubuntu/).
Thanks to pneumee.
The issue was because I was using my mongolab.com username and password, instead of the database username and password.
It is working now.
OK - I figured it out and would also like to add onto pneumee's answer.
Go to mongolab.com
Login.
Navigate to the "Users" tab.
If you have forgotten your Username and Password for the database, I suggest you "Add a new user" and supply it with the username and password.
default users in db
login: admin
password: admin
check users in
https://mongolab.com/databases/MYDBNAME#users
my problem was being putting login and password mongolab

Mongorestore "auth fails" at deployed app at meteor.com

I received the information from my deployed app by using the command
meteor mongo -url bhedir.meteor.com
I then took the response and used the info for my
mongorestore -u client -p meteorinfo - h meteorinfo -d bhedir_meteor_com meteordump/meteor
however, I keep getting the following error:
assertion: 18 { code: 18, ok: 0.0, errmsg: "auth fails" }
I should note that I have several meteorite packages included but I don't see how that would affect this.
Also, I've done this before, granted not that many times, but did not run into any issues. Any advice would be greatly appreciated.
I assume 'meteorinfo' is a placeholder for the hostname and password you get out?
If so then when you get the auth info with meteor mongo -url bhedir.meteor.com you have to be very quick to do the mongorestore as the auth data you get only lasts 1 minute, then it expires and you have to do the meteor mongo --url bhedir.meteor.com call again
You forgot some required parameter as might be the username, password or db