Lggoch
Lggoch

Reputation: 71

Not autorized to execute any command using Service Connector on MongoDB

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

Upvotes: 2

Views: 122

Answers (2)

Sybil
Sybil

Reputation: 2592

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.

Upvotes: 4

Sandro Mathys
Sandro Mathys

Reputation: 474

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.

Upvotes: 4

Related Questions