MongoDB Default Username and Password

Tahseen Tauseef May 11, 2022
  1. Default Username and Password in MongoDB
  2. Authorize MongoDB
  3. Find Your Password in MongoDB
MongoDB Default Username and Password

In this tutorial, we’ll discuss the default username and password and how to find a username and password in MongoDB.

Default Username and Password in MongoDB

By default, MongoDB does not have access control enabled, so there is no default user or password. Use the command line option --auth or the security.authorization configuration file setting to enable access control.

The following are the steps that you can follow. First, open a terminal and start MongoDB Daemon.

mongod --port 27017 --dbpath /data/db

Enter the mongo shell in a new terminal tab.

 mongo --port 27017

Create an admin user.

use admin
    user: "user123",
    pwd: "pass123",
    roles: [ { role: "userAdminAnyDatabase", db: "admin" },
             { role: "dbAdminAnyDatabase", db: "admin" },
             { role: "readWriteAnyDatabase", db: "admin" }

Enter quit() exit. Press and hold ctrl-c to kill the process on the mongo daemon page, and restart MongoDB with the --auth option enabled.

$ mongod --auth --port 27017 --dbpath /data/db
2019-02-23T16:18:38.539+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-02-23T16:18:38.553+0800 I CONTROL  [initandlisten] options: { net: { port: 27017 }, security: { authorization: "enabled" }, storage: { dbPath: "/data/db" } }

Log in to the mongo shell with the user-created earlier.

$ mongo --port 27017 -u "user123" -p "pass123" --authenticationDatabase "admin"
MongoDB shell version v4.0.2
connecting to: mongodb : //
MongoDB server version: 4.0.2

Select Username/Password (MONGODB-CR/SCRAM-SHA-1) to connect to your MongoDB deployment.

  1. Check Username/Password (MONGODB-CR/SCRAM-SHA-1) or Username/Password (SCRAM-SHA-256) from Agent Auth Mechanism. Cloud Manager automatically generates the Agents’ usernames and passwords.
  2. Click Save.



Parameters for the query are Name, Description, and Type: username. You must have the viewUser action on the other user’s database to view another user’s information.

Below is the query to change a MongoDB user’s password.


db.changeUserPassword("user", "12345");

Authorize MongoDB

  1. Start MongoDB without authentication.
  2. After that, connect to the server using the mongo shell.
  3. Create the user administrator.
  4. Enable authentication in the MongoDB configuration file.
  5. Now connect and authenticate as the user administrator.
  6. Finally, create additional users as needed.

Find Your Password in MongoDB

You can specify the password directly as you would with earlier versions of the mongo shell. A user document contains the username and password, optionally, the authentication mechanism, and a digest password flag.

The user’s name with access privileges for the given database and the user’s password.

Related Article - MongoDB Authentication