How it works...
This is a fairly straightforward recipe. We begin by shutting down the mongod instance and starting it again without the --auth parameter. By doing so, we start the mongod instance without authentication support. Next, in step 3, we switch to the admin database and, in step 4, we execute a find() query to search for any users who already have the root built-in role assigned to them.
In step 6, we execute the db.changeUserPassword() command with the target username and its new password. Once we are done, we can stop and start the mongod instance again, this time with the --auth parameter to ensure that authentication is enabled.
On a running system, if you already have an administrative user, you can change any user's password ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access