Unable to access databases other than 'admin' as user 'admin' with --auth

197 views
Skip to first unread message

Peter Kleiweg

unread,
Oct 27, 2012, 9:04:00 AM10/27/12
to mongodb-user
I have mongod running with --auth.
The admin user is named 'admin'.
I can log-in in database 'admin', but can't access any of the other
databases.

Example:

$ mongo --port 27019 admin
MongoDB shell version: 2.2.0
connecting to: 127.0.0.1:27019/admin
> db.auth("admin", "XXXXXXXXXXX")
1
> db = connect("127.0.0.1:27019/test")
connecting to: 127.0.0.1:27019/test
test
> db.test.findOne()
Sat Oct 27 14:54:19 uncaught exception: error {
"$err" : "unauthorized db:test ns:test.test lock type:1
client:127.0.0.1",
"code" : 10057
}
> db.auth("admin", "XXXXXXXXXXX")
Error: { errmsg: "auth fails", ok: 0.0 }
0

Andre de Frere

unread,
Oct 28, 2012, 10:23:56 PM10/28/12
to mongod...@googlegroups.com
Hi Peter,

This is because you are creating a new connection with your code:

db = connect("127.0.0.1:27109/test")

If you create a new connection, you have to authorise that connection.

In this case it looks like you are just trying to query databases on the same server, so you can just "use" the database you want to query rather than open a new connection to the same server you are currently on:

MongoDB shell version: 2.2.0
connecting to: 127.0.0.1:27019/test
> use admin
switched to db admin
> db.auth("admin",XXXXXXX)
1
> use test
switched to db test
> db.test.findOne()
{ "some":"results"}

 Regards,
André
Message has been deleted

Tom Vo

unread,
Oct 28, 2012, 10:33:11 PM10/28/12
to mongod...@googlegroups.com
Hi Peter

You could use command "use test" or "db = db.getSiblingDB('test')" to switch to test database after you authorized admin db.

Example:

    $ mongo --port 27019 admin
    MongoDB shell version: 2.2.0
    connecting to: 127.0.0.1:27019/admin

    db.auth("admin", "XXXXXXXXXXX")
    
   use test
   db.test.findOne()

Best Regards

--
You received this message because you are subscribed to the Google
Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com
To unsubscribe from this group, send email to
mongodb-user...@googlegroups.com
See also the IRC channel -- freenode.net#mongodb



--

Thanks and Best Regards
-------------------------------------------------------------------------------------------------------------
Vo Tan Hau (TOM)
Senior Database Administrator
NEXCEL SOLUTIONS LTD
SMS Tower,Lot 40, Quang Trung Software City, District 12, HCMC, Vietnam.
Tel:+84-8-37154278 - Fax:+84-8-37154279 www.nexcel.vn
Messenger
(Skype+Yahoo+Live): Vohau2002


Peter Kleiweg

unread,
Oct 29, 2012, 12:51:57 PM10/29/12
to mongodb-user
On 29 okt, 03:33, Tom Vo <tom...@nexcel.vn> wrote:
> Hi Peter
>
> You could use command "use test" or "db = db.getSiblingDB('test')" to
> switch to test database after you authorized admin db.

Thanks.
I new about "use test", but can't use it, because I need it in a
script. But db.getSiblingDB() works perfectly.
Reply all
Reply to author
Forward
0 new messages