Where MongoDB stores your credentials
MongoDB usernames and passwords are not stored in a single central location the way they are in some other databases. Instead, they live in the MongoDB server itself, in a system database called admin. If you set up MongoDB on your own computer or server, you created these credentials during installation. If your MongoDB is hosted by a provider like MongoDB Atlas, your credentials are in your account dashboard, not on the server.
The method to retrieve them depends on where your MongoDB is running. A local installation on your machine requires different steps than a cloud-hosted database. Knowing which one you have is the first step.
Key Takeaways
- MongoDB credentials are stored in the admin database on the server itself, not in a configuration file you can read directly.
- If you use MongoDB Atlas (the official cloud service), your username and password are in your account settings, not retrievable from the server.
- For a local MongoDB installation, you can reset the admin password through the MongoDB shell if you have server access.
- The username is often "admin" by default, but custom usernames created during setup will not appear in plain text anywhere.
- If you have lost credentials to a production database, contact your hosting provider or database administrator rather than attempting to reset them yourself.
Retrieving credentials from MongoDB Atlas
If your MongoDB is hosted on MongoDB Atlas, log into your Atlas account at mongodb.com. Click on your project name, then go to the Database Access section in the left sidebar. You will see a list of database users with their usernames. The password is not displayed here — it was shown only once when you created the user.
If you need the password and do not have it written down, you must create a new user. Click "Add New Database User," choose a username and password, and note them before confirming. This new user will have the same permissions as the old one if you assign it the same role. You can then delete the old user from this same Database Access page.
Your connection string (which includes the username and password in the format mongodb+srv://username:password@cluster.mongodb.net) is found in the Clusters section. Click "Connect" on your cluster, then "Connect Your process," and copy the connection string. Replace <password> with your actual password.
Resetting credentials on a local MongoDB installation
If MongoDB is running on your own computer or a server you control, and you have lost the password, you can reset it through the MongoDB shell. First, stop the MongoDB service. On Windows, open Services and stop MongoDB. On Mac or Linux, run sudo systemctl stop mongod or brew services stop mongodb-community.
Restart MongoDB without authentication by running mongod --noauth on the command line (or add --noauth to your startup command). Open a new terminal and connect to MongoDB with mongo or mongosh (depending on your version). You are now connected without a password.
Switch to the admin database by typing use admin. Then run db.changeUserPassword("admin", "newpassword"), replacing "newpassword" with what you want. Stop the MongoDB process and restart it normally without the --noauth flag. You can now log in with the username "admin" and your new password.
Finding the username when you know the password
If you remember your password but not the username, the approach depends on where the database is hosted. For MongoDB Atlas, the username is always visible in the Database Access section of your account, even though the password is hidden.
For a local installation, connect to MongoDB with mongo or mongosh and run use admin followed by db.getUsers(). This shows all users in the admin database with their usernames and roles. If you created additional users in other databases, switch to that database with use databasename and run db.getUsers() again.
What to do if you cannot access the server
If your MongoDB is hosted by a third party and you have lost both username and password, contact your hosting provider's support team. They can verify your account ownership and reset credentials for you. Do not attempt to bypass authentication on a server you do not own.
If the database is on a server you own but you cannot access the server itself (for example, you lost SSH access), you will need to regain server access first. This usually means contacting your hosting provider with proof of ownership. Once you have server access, you can follow the local reset steps above.
Preventing credential loss in the future
Write down your MongoDB username and password in a password manager like Bitwarden, 1Password, or KeePass rather than in a text file. Password managers encrypt your credentials and let you retrieve them from any device. If you use MongoDB Atlas, save your connection string in the same place.
If you manage multiple databases, create a spreadsheet or document in your password manager that lists which database each credential belongs to, what it is used for, and when it was last changed. This takes five minutes and saves hours of troubleshooting later.
Frequently Asked Questions
Can I see my MongoDB password in plain text anywhere?
No. MongoDB does not store passwords in plain text, and they are not displayed in configuration files or logs. If you have lost your password, you must reset it by creating a new one. For Atlas, this means creating a new database user. For local installations, you can reset the admin password through the MongoDB shell.
What is the default MongoDB username and password?
MongoDB has no default username or password. If you installed MongoDB without creating a user, the server runs without authentication enabled. If you set up authentication during installation, you chose the username and password yourself. If you cannot remember what you chose, you will need to reset it.
Do I need a different username and password for each database?
No. A single MongoDB user can access multiple databases if you grant them the right roles. Most setups use one admin user for all databases. You can create additional users with limited permissions for specific databases if you want to restrict access.
Why does MongoDB Atlas not show my password after I create it?
MongoDB Atlas shows the password only once, when you first create the user. This is a security practice — if the password were stored and displayed in your account, anyone with access to your account could see it. If you lose it, you must create a new user instead of retrieving the old one.
Can I change my MongoDB username?
You cannot rename an existing user in MongoDB. If you want a different username, create a new user with the new name and the same role, then delete the old user. For MongoDB Atlas, do this in the Database Access section. For local installations, use the MongoDB shell commands db.createUser() and db.dropUser().