V
V
Vladimir T.2014-01-18 10:25:59
MongoDB
Vladimir T., 2014-01-18 10:25:59

mongodb: authentication problem

There is mongo on a separate server. Created user:

db.addUser( { user: "<username>",
              pwd: "<password>",
              roles: [ "userAdminAnyDatabase" ] } )

Enabled the auth = true parameter in the config
I go to the cli
mongo --host <host> --port <port> -u <username> -p <password> --authenticationDatabase admin <dbname>

I'm trying to make a request:
db.<collection>.find()
I get:
error: { "$err" : "not authorized for query on <dbname>.<collection>", "code" : 16550 }

What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
X
xPutnikx, 2014-05-16
@vachuahe

Just ran into the same problem today. I used mongodb 2.6.1, its difference is that compared to 2.4.x, the users model in admin.system.users has changed and, accordingly, the system of rights and roles.
In order for the user to read the data, the following roles were added.

{
        "user" : "<username>", 
        "db" : "<db_name>", 
        "credentials" : { "MONGODB-CR" : "xxxxxxxx" },
        "roles" : [
            { "role" : "dbAdmin", "db" : "<db_name>" }, 
            { "role" : "readWrite", "db" : "<db_name>" }, 
            { "role" : "userAdminAnyDatabase", "db" : "admin" } 
        ] 
    }

The API for creating a user has also changed. Instead of addUser, createUser is now used from the database for which this user needs to be added.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question