2

I am using the MongoDB on my app and when I try to access the database directly using the service connector, I am able to connect but then I am getting :

Error: error: {
    "ok" : 0,
    "errmsg" : "not authorized on admin to execute command { *any command*}",
    "code" : 13
}

and this on any query or command.

Is there a way to change authorization or accessing the data of my MongoDB

P.S: My MongoDB was bind as in the tutorial: https://docs.developer.swisscom.com/tutorial-python/bind-service.html

Joundill
  • 6,828
  • 12
  • 36
  • 50
Lggoch
  • 71
  • 4
  • please format code help [here](https://stackoverflow.com/help/privileges/comment), add all correspond tags to the question (it will better match on tag in search) – Sergii Jul 25 '17 at 15:55

2 Answers2

4

It looks like you're trying to execute commands on the admin database on which your user is not authorized. You can find the correct database which your user is authorized on in the credentials (key mongodb.credentials.database) but ideally you connect using the provided URI (mongodb.credentials.uri) which will connect you to the correct database automatically.

You can have a look at the Python example in the tutorial you linked to find out how to access and use those credentials correctly.

Sandro Mathys
  • 474
  • 3
  • 7
4

The answer from Sandro Mathys is correct and helpful, I wish to clarify/simplyfy a little bit.

The service broker grants you the Role dbOwner and creates a database with random name for you. This is done during cf create-service process.

The database owner can perform any administrative action on the database. This role combines the privileges granted by the readWrite, dbAdmin and userAdmin roles.

You have no privileges on admin database. The admin database is only for Swisscom operators. Please use for login with mongo shell the parameter --authenticationDatabase with the random database name from cf env.

Specifies the database in which the user is created. See Authentication Database.

If you do not specify a value for --authenticationDatabase, mongo uses the database specified in the connection string.

Sybil
  • 2,503
  • 3
  • 25
  • 36
  • Thank you. the procedure is now working. I noticed that by typing 'use admin' I was switching database. However at te beginning it was still not working but I generated a new service_key and it is now working well. Thanks again – Lggoch Jul 27 '17 at 13:09