Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't authorize to newly created MongoLabs DB

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

like image 637
cachvico Avatar asked Jan 13 '23 13:01

cachvico


1 Answers

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).

like image 110
cachvico Avatar answered Jan 21 '23 11:01

cachvico