1

I have a MongoDB that has the regular authentication setup so you need a username and password to connect to the database (auth=true in the configs). The problem I'm running in to is that I have some scripts that need to connect to that database and then create a new one, copy some data over, and later remove the database at some point in time. The issue is that the user for the primary database doesn't seem to be able to create a new one.

I've dug through their documentation but haven't been able to find anything yet. I would liken what I'm looking for to giving a MySQL user the ability to create database and drop database.

2 Answers 2

4

This looks to need several different privs.

  • clusterAdmin: dropDatabase, which allows removing any database.
  • Any Database Roles: readWriteAnyDatabase, which allows reading and writing from Any database; required to operate on dynamically created databases.

I haven't figured out what you need to create a database, but that right may inherit directly from readWriteAnyDatabase.

2

You should have one "root" user (like in MySQL) and use him for management/operational tasks:

db.addUser({user: "root", pwd: "123456", roles: [ "userAdminAnyDatabase", "readWriteAnyDatabase", "dbAdminAnyDatabase", "clusterAdmin" ]})) // change PW

This user will be able to do anything:

  • create/change users
  • create/drop DBS
  • dump/restore

Please note that you should also add:

setParameter = enableLocalhostAuthBypass=0

to prevent local users from being "root" when connecting from localhost.

Normal users (non-admin) should then have at most the following privileges:

"read", "readWrite", "dbAdmin"

More information can be found here: http://docs.mongodb.org/manual/reference/user-privileges/

Edit: clusterAdmin is to create DBs...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .