0
votes

I have mongodb server with auth=true and many databases. I'm trying to connect to it remotely using admin database:

mongo --host xxx admin --username admin --password secretPassword

(WORK)

 mongo --host xxx products --username admin --password secretPassword

(DOESN'T WORK)

I can connect to admin database and switch to products. But developers using connection string to connect to specific database using same username and password.

I can create admin user for each database but databases are pretty dynamic some added some removed. I've read thread about global admin but set up user role doesn't help

roles: [ { role: "userAdminAnyDatabase", db: "admin" } ] 

and

--authenticationDatabase

Is not an option because a lot of code has to be rewritten.

Is there a way to setup one global admin that anyone can connect to remote database with username and password?

1
What does this have to do with Python?Cyphase
I will second that comment. If your actual question is about connecting Python clients using authentication then you should get to the pointBlakes Seven

1 Answers

0
votes

If you are using MongoDB 3.0+, the default location for users is the admin database. You will have to use --authenticationDatabase in this case going forward anyway.

With centralized users, you can define roles with access to all databases as necessary:

https://docs.mongodb.org/manual/reference/built-in-roles/

It sounds like you may want to refactor the database connection code, especially if "a lot of code" has to be rewritten, that sounds like you haven't been following DRY--"don't repeat yourself" principles.