Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB not authorized for query - code 13

In MongoDB 2.6.1 I've setup a user with dbAdmin rights:

{         "_id" : "mydbname.myusername",         "user" : "myusername",         "db" : "mydbname",         "credentials" : {                 "MONGODB-CR" : "<some credentials>"         },         "roles" : [                 {                         "role" : "dbAdmin",                         "db" : "mydbname"                 }         ] } 

When I use the mongo shell to connect to the database (using -u and -p on command line) and run a query like this:

db.mycollectionname.find() 

I get this error:

error: { "$err" : "not authorized for query on mydbname.request", "code" : 13 } 

Any ideas what can be happening?

So far I've tried adding every role I can find to the user but that hasn't helped.

like image 656
Guy Avatar asked May 12 '14 21:05

Guy


2 Answers

You need to assign the read role to the user in question.

The dbAdmin role does not include read access on non-system collections.

like image 97
Sebastian Avatar answered Sep 30 '22 14:09

Sebastian


For anybody running into this problem against Mongo 3.0.6, I fixed by adding

?authMode=scram-sha1 

at the end of my mongodb uri.

Here are some docs explaining the purpose of scram-sha1

like image 35
ticofab Avatar answered Sep 30 '22 13:09

ticofab