Introducing Dragonfly Cloud! Learn More

Question: How to change a MongoDB cluster password?


Changing the password for a MongoDB cluster involves updating the credentials for the database user(s) associated with that cluster. The process can differ slightly based on the environment (Atlas, self-hosted, etc.). Below are steps for both MongoDB Atlas and a self-hosted MongoDB cluster.

MongoDB Atlas

  1. Log into MongoDB Atlas: Navigate to the MongoDB Atlas dashboard.

  2. Access the Database Access Page: On the left sidebar, click on 'Database Access' under the 'Security' section.

  3. Edit User Credentials: Locate the database user whose password you want to change. Click on the 'Edit' button next to the user.

  4. Update the Password: In the user edit form, you will find an option to change the password. Enter the new password and confirm it.

  5. Save Changes: After entering the new password, save the changes.

This updates the password for the MongoDB Atlas cluster's user. Remember to update your application or service with the new password to maintain access to the database.

Self-Hosted MongoDB Cluster

For a self-hosted MongoDB setup, you need to use the MongoDB shell or a GUI tool that connects to your database.

Using MongoDB Shell

  1. Connect to MongoDB: Open your terminal and connect to your MongoDB instance using the mongo shell command.

    mongo -u yourUserName -p yourPassword --authenticationDatabase admin
  2. Switch to the Admin Database:

    use admin
  3. Update the User's Password: Use the db.changeUserPassword() function to change the password of a user.

    db.changeUserPassword('yourUserName', 'newPassword')

Replace 'yourUserName' with the username of the database user and 'newPassword' with the desired new password.

This method directly updates the password in the MongoDB cluster for the specified user. It's essential to reconnect any applications or services using this user's credentials with the updated password.


Changing a MongoDB cluster password is straightforward, whether you're using MongoDB Atlas or managing a self-hosted cluster. Always ensure passwords are strong and updated regularly as part of good security practices.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.