4

I am trying to drop the local database in my replica set so that I can rename the replica set, but I keep getting the below error

errmsg" : "not authorized on local to execute command { dropDatabase: 1.0, lsid: { id: UUID(\"4a92bd75-2e25-4fab-abd7-2d72f65050c7\") }, $db: \"local\" }"

I am using a user who has root privileges and I am using MongoDB 4.0. Anyone know why this is happening?

siddhu
  • 195

2 Answers2

5

These suggestions weren't working for me in Mongo 5.0.8, setting authorisation to not enabled didn't allow me to drop the local database, adding root role to my user didn't allow me to drop the database, but this was the solution

use admin;
db.grantRolesToUser("adminUser", ["__system"]);
use local
db.dropDatabase()
use admin;
db.revokeRolesFromUser("adminUser", ["__system"]);

and then running looks like this

local> use admin;
switched to db admin
admin> db.grantRolesToUser("adminUser", ["__system"]);
{ ok: 1 }
admin> use local
switched to db local
local> db.dropDatabase()
{ ok: 1, dropped: 'local' }
local> use admin;
switched to db admin
admin> db.revokeRolesFromUser("adminUser", ["__system"]);
{ ok: 1 }
1

From Mongo documentation, although your user has root role, you can't interact with local and config databases. You'll need to create a new user with dbAdmin role in the local database. This change was implemented from Mongo 3.4

Another approach is to disable authorization from the security section in /etc/mongod.conf

security:
  authorization: disabled

This way an anonymous user can perform any action on any database. This one is less recommended unless you are the only one having access to the Mongo node. Just make sure to reactivate it once you're done removing local database.