Answer the question
In order to leave comments, you need to log in
How does authorization work in Mongo?
Hello.
The server has mongo version 2.4.9 installed.
By default, the auth=true line in the config is commented out.
Users created in mongo:
> use admin
switched to db admin
> show users
{
"_id" : ObjectId("55631c4ced1bdfc880fda8e0"),
"user" : "admin",
"pwd" : "f306c561a12b1be8478e4cc3b460433a",
"roles" : [
"userAdminAnyDatabase",
"dbAdminAnyDatabase",
"readWriteAnyDatabase"
]
}
{
"_id" : ObjectId("5563371cb7537b3e14bdfb4b"),
"user" : "rUser",
"pwd" : "eee18df57c91293310dbf78649955a84",
"roles" : [
"readAnyDatabase"
]
}
> use admin
switched to db admin
> db.auth('admin', 'password')
1
> show dbs
Tue May 26 19:48:05.074 listDatabases failed:{ "ok" : 0, "errmsg" : "unauthorized" } at src/mongo/shell/mongo.js:46
Answer the question
In order to leave comments, you need to log in
Works for me:
Started the server:
I add a user:
$ mongo --port 27020
MongoDB shell version: 2.6.10
connecting to: 127.0.0.1:27020/test
> show dbs
admin (empty)
local 0.031GB
> use admin
switched to db admin
> db.addUser({user:'name', pwd:'password', roles:["userAdminAnyDatabase","dbAdminAnyDatabase", "readWriteAnyDatabase"]})
WARNING: The 'addUser' shell helper is DEPRECATED. Please use 'createUser' instead
Successfully added user: {
"user" : "name",
"roles" : [
"userAdminAnyDatabase",
"dbAdminAnyDatabase",
"readWriteAnyDatabase"
]
}
> exit
bye
$ mongo --port 27020
MongoDB shell version: 2.6.10
connecting to: 127.0.0.1:27020/test
> show dbs
2015-05-27T16:35:46.071+0500 listDatabases failed:{
"ok" : 0,
"errmsg" : "not authorized on admin to execute command { listDatabases: 1.0 }",
"code" : 13
} at src/mongo/shell/mongo.js:47
> use admin
switched to db admin
> db.auth('name', 'password')
1
> show dbs
admin 0.031GB
local 0.031GB
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question