my question is - is it possible to define user in the Mongo database who will be able to drop the database? Maximum user privilege is "dbAdmin" but that privilege doesn't allow users to drop the database, only collections can be dropped.

I know that "clusterAdmin" has rights to drop the database, but that role can't be defined in regular database, only in admin database...


No, it is not currently possible (in version 2.4) to create such a user/permission.

Permissions on a specific database grant permissions on entities contained in that database, but not on the database itself. Cluster level permission is needed to create or drop databases.

Reference: http://docs.mongodb.org/manual/reference/user-privileges/#database-administration-roles

| improve this answer | |

Grant your user the "root" role and you will be able to delete the dbs. You do NOT have to disable authentication to do this, as long as you have an admin account this will work.

use admin;
db.grantRolesToUser("adminUser", ["root"]);

Now delete the database

use databaseToDelete;
| improve this answer | |
  • This worked for me on MongoDB 4.4, except it's dropDatabase, not deleteDatabase there. – chris6953 11 hours ago

Though the answer from Asya will work, one quick was is to remove authentication from mongod.conf or start the server without authentication.

Then go to the database and drop the database. Restart the server with authentication.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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