Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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
add comment

2 Answers

up vote 3 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
add comment

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...

share|improve this answer
add comment

Your Answer

 
discard

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.