1

I have forgot my mongodb root user password for the shared cluster of 3 nodes. I have gone through stack overflow for the same issue but was unable to replicate due to different configuration. Below is my configuration

  1. mongodb version 4.4.
  2. replication on 3 servers(nodes) using keyfile authentication.
  3. all nodes are running in docker containers.

In case useful, I have other credentials that were created through root user for backup and read write permission but they dont have access to admin database.

Please guide me if you have any solution. thanks

unable to find anything to try

1 Answers1

0

The official way of doing this is:

Restart the MongoDB without authorization, i.e. mongod --noauth ... or via configuration file

security:
   authorization: disabled

Then you can logon without password and change credentials of the root user.

Attention: while the MongoDB is running without authorization, every user connects with root privileges, so you better restart the MongoDB in maintenance mode, i.e.

net:
   bindIp: localhost
   port: 55555

#replication:
#   replSetName: shardA

#sharding:
#   clusterRole: shardsvr

setParameter:
   skipShardingConfigurationChecks: true
   disableLogicalSessionCacheRefresh: true

Then you can connect only from localhost using port 55555 (which is not configured by other cluster members nor known by other users)

You need to do this only on the configuration server, because user accounts are stored there, not on the shards or mongos members.

However, there is a much simpler way to achieve the same, use the keyfile for authentication:

mongosh --authenticationDatabase local -u __system -p "$(tr -d '\011-\015\040' < /path/to/keyfile)"
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
  • hi @Wernfried Domscheit, thanks for the response. I have gone through all of the solutions you provided and below are the output that i got 1. Using the keyfile throws and error i.e. Error: Error preflighting normalization: U_STRINGPREP_PROHIBITED_ERROR : connect@src/mongo/shell/mongo.js:374:17 @(connect):2:6 exception: connect failed exiting with code 1 – Jony Chawla Nov 08 '22 at 05:48
  • Please see my update. `tr` is just used to remove newline and other special characters, you may try keyfile content manually with copy/paste. If you go for restart, try option [--transitionToAuth](https://www.mongodb.com/docs/v4.4/reference/program/mongod/#std-option-mongod.--transitionToAuth) – Wernfried Domscheit Nov 08 '22 at 06:47