Setting up MongoDB for multi-db authentication

mongodb

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.

Best Answer

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.

Related Topic