HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Mongo authentication user can't drop database

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
canusermongoauthenticationdatabasedrop

Problem

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

Solution

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;
db.dropDatabase();

Code Snippets

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

Context

StackExchange Database Administrators Q#45735, answer score: 10

Revisions (0)

No revisions yet.