4

I am trying to start with MongoLab. Using the mongo shell it seems I cannot auth to any DB I create, even with a brand new account and DB.

I created the MongoLab user with the same username and password as my DB user, so I'm sure there are no username/password mistakes.

# connect to mongod v2.4.3 using 2.4.3 client:
#
imac ~/Desktop/mongodb-osx-x86_64-2.4.3/bin$ ./mongo ds059557.mongolab.com:59557/cachv -u redacted -p redacted
MongoDB shell version: 2.4.3
connecting to: ds059557.mongolab.com:59557/cachv
> use mydb
switched to db mydb
> db.things.insert({f:1})
not authorized for insert on mydb.things

or

# connect to mongod v2.2.4-rc0 using 2.4.3 client:
#
imac ~/Desktop/mongodb-osx-x86_64-2.4.3/bin$ ./mongo dbh83.mongolab.com:27837/cachv2 -u redacted -p redacted
MongoDB shell version: 2.4.3
connecting to: dbh83.mongolab.com:27837/cachv2
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
Error while trying to show server startup warnings: need to login
> use mydb
switched to db mydb
> db.things.insert({f:1})
Sat Apr 27 05:46:32.456 JavaScript execution failed: getlasterror failed: { "errmsg" : "need to login", "ok" : 0 } at src/mongo/shell/db.js:L698
> db.auth('redacted','redacted')
Error: 18 { errmsg: "auth fails", ok: 0.0 }
0

followed on a second attempt by:

imac ~/Desktop/mongodb-osx-x86_64-2.4.3/bin$ ./mongo dbh83.mongolab.com:27837/cachv2 -u redacted -p redacted
MongoDB shell version: 2.4.3
connecting to: dbh83.mongolab.com:27837/cachv2
Error while trying to show server startup warnings: need to login

Finally, I downloaded the older 2.2.4 client, but still not luck:

# connect to mongod v2.2.4-rc0 using 2.2.4 client:
#
mac ~/Desktop/mongodb-osx-x86_64-2.2.4/bin$ ./mongo dbh83.mongolab.com:27837/cachv2 -u redacted -p redacted
MongoDB shell version: 2.2.4
connecting to: dbh83.mongolab.com:27837/cachv2
> use mydb
switched to db mydb
> db.things.insert({'g':1})
Sat Apr 27 06:00:30 uncaught exception: getlasterror failed: { "errmsg" : "need to login", "ok" : 0 }
> db.auth('redacted','redacted')
Error: { errmsg: "auth fails", ok: 0.0 }
0
> db.things.insert({'g':1})
Sat Apr 27 06:00:47 uncaught exception: getlasterror failed: { "errmsg" : "need to login", "ok" : 0 

Are there any additional ports that have to be opened at my end?

Can anyone help?

Thank you!

Darren

Dagrada
  • 1,135
  • 12
  • 22
  • normally when you start mongod with --auth the first thing you have to do is connect to admin db and create admin user - then you can use admin user to authenticate yourself to any db or you can create another user for yourself to use. – Asya Kamsky Apr 27 '13 at 14:26
  • 2
    I got it - this is because your username and password only work to db named 'cachv' - that's the DB that was created when you configured things in the UI. Definitely not a general mongodb problem. – Asya Kamsky Apr 27 '13 at 14:41
  • I created my sandbox via Azure store. MongoLab never told me my credentials or that I needed to create an 'admin' user. It appears to work fine when you put all of the pieces together. – Mark Good Nov 09 '14 at 12:35

1 Answers1

9

Ok! I fixed it.

For some reason -u and -p wasn't working for me, and further it seems that calling db.auth() must be called as the first command in the shell after connecting.

Further, for pymongo, it seems the username/password parsed from the server string wasn't working, and instead I had to call db.authenticate(user, password).

Dagrada
  • 1,135
  • 12
  • 22