Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer

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:

Edit: clusterAdmin is to create DBs...

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.