How can MongoDB enable authentication without downtime?

My company uses MongoDB as the primary database for our production environment, currently running version 4.0. We are planning to upgrade to the latest version, 6.0. Additionally, our existing replica set doesn’t have authentication enabled, and I would like to add SCRAM authentication during the upgrade process. However, I’ve found that it’s not possible to add authentication without stopping the database. Is there a solution that can meet my requirements?

  • Upgrade to the latest version.
  • Add SCRAM authentication.
  • Keep the database running during the upgrade process (failover for the primary node is acceptable).

Who says there has to be downtime?

But i suggest that you finish the upgrade first and then enable auth. Do one thing at a time and do it well.

I apologize for any inaccuracies in my previous description. To clarify, as far as I know, if a MongoDB replica set is not initially configured with authentication, enabling authentication later on will result in all existing connections being terminated. This means that while MongoDB itself will not be stopped, any application services relying on it will be disrupted. I’m looking for a way to avoid this situation.

I have found the tutorial for the solution, thanks a lot