Can't delete database "training"

As I was completing the course, I created a database called “training” to experiment. Now I cannot delete it. I searched the internet and this forum looking for answers.

I tried dropDatabase

Atlas atlas-k14rbk-shard-0 [primary] training> db.dropDatabase()
MongoServerError: user is not allowed to do action [dropDatabase] on [training.]

Then I tried to change the roles of my user

Atlas atlas-k14rbk-shard-0 [primary] training> db.grantRolesToUser("m001-student", [ {role: "dbAdminAnyDatabase", db: 'training'}]);
MongoServerError: CMD_NOT_ALLOWED: grantRolesToUser

I know I can delete the database on the web interface, but I was curious to know how to delete it using mongoshell.

Hi @Jaume_Barcelo_Vicens, welcome to the community :wave: .
Can you check whether the Database User you are connecting with has the atlasAdmin role? Because the error you have mentioned is expected when a user has readWriteAnyDatabase built-in role assigned to them. Read Write To Any Database role allows you to:

But doesn’t provide you the privilege to drop a database. To get the dropDatabase privilege, you need the atlasAdmin built-in role.
The Atlas Admin role comes with the following privilege actions and inherited roles:

Please use this role with caution :warning: and only when the above privileges are required in order to protect your database from any accidental and unauthorized actions on your database deployment.

Learn more about Atlas Built-In Roles.

If you have any doubts, please feel free to reach out to us.

Thanks and Regards.
Sourabh Bagrecha,


Thank you, SourabhBagrecha.

I followed your instructions and it worked. I used Atlas’ web interface to create a new user “m001-admin” with the atlasAdmin role. Then I connected with this new user.

Atlas atlas-10ti99-shard-0 [primary] training> db.getUser('m001-admin')
  _id: 'admin.m001-admin',
  user: 'm001-admin',
  db: 'admin',
  roles: [ { role: 'atlasAdmin', db: 'admin' } ]

Finally I deleted the “training” database.

Atlas atlas-10ti99-shard-0 [primary] training> db.dropDatabase()
{ ok: 1, dropped: 'training' }
1 Like