10

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

asked Jul 4, 2013 at 12:08
0

4 Answers 4

8

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

answered Jul 4, 2013 at 19:52
10

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();
answered May 2, 2019 at 2:54
0
1

One could use the dbOwner role

The database owner can perform any administrative action on the database. This role combines the privileges granted by the readWrite, dbAdmin and userAdmin roles.

E.g: creating a user:

db.createUser(
 {
 user: "myusername",
 pwd: "mypassword-to-change",
 roles: [
 {
 role: "dbOwner",
 db: "mydatabase"
 }
 ]
 }
)
answered May 18, 2022 at 23:07
0

Though the answer from Asya will work, one quick way 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.

Paul White
95.3k30 gold badges439 silver badges689 bronze badges
answered Feb 3, 2017 at 7:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.