Restoring access if you are locked out
In this recipe, we will look at how to restore the password for a super administrator user.
Getting ready
You should have a MongoDB instance with authentication enabled and an administrator account created. Refer to the Setting up authentication in MongoDB and creating a superuser account recipe of this chapter.
How to do it...
- Shut down the mongod instance.
- Start the mongod instance without the
--auth
parameter:
mongod --dbpath /data/db
- Switch to the
admin
database:
use admin
- Find the administrative user:
db.system.users.find({'roles.role': "root"})
- You should see an output similar to this:
{ "_id" : "admin.superadmin", "user" : "superadmin", "db" : "admin", "credentials" : { "SCRAM-SHA-1" : { "iterationCount" : 10000, "salt" : "X3IUy53syah8GEZozwwCPA==", "storedKey" : "nzGTHW7yeKUjGxYWEJNkCkzcQZU=", "serverKey" : "HiUfRvoW4MyiOQvtWk3FbLy4bvg=" } }, "roles" : [ { "role" : "root", "db" : "admin" }...