MongoDB default username and password
In this article, we will discuss the default username and password and how to find 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.
Here are the steps you can follow. First, open a terminal and start the MongoDB daemon.
mongod --port 27017 --dbpath /data/db
Enter the mongo shell in a new terminal tab.
mongo --port 27017
Create an administrator user.
use admin
db.createUser(
{
user: "user123",
pwd: "pass123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" },
{ role: "dbAdminAnyDatabase", db: "admin" },
{ role: "readWriteAnyDatabase", db: "admin" }
]
}
)
Type quit()
quit. Press 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" } }
Login to the mongo shell using the user created earlier.
$ mongo --port 27017 -u "user123" -p "pass123" --authenticationDatabase "admin"
MongoDB shell version v4.0.2
connecting to: mongodb : //127.0.0.1:27017/
MongoDB server version: 4.0.2
...
Select Username/Password (MONGODB-CR/SCRAM-SHA-1) to connect to your MongoDB deployment.
- Checks the Username/Password (MONGODB-CR/SCRAM-SHA-1) or Username/Password (SCRAM-SHA-256) from the proxy authentication mechanism. Cloud Manager automatically generates the username and password for the proxy.
- Click Save.
grammar:
db.getUser(username)
The parameters for the query are name, description, and type: username. You must execute the viewUser operation on the database of another user to view another user's information.
Below is the query to change the MongoDB user password.
Query:
db.changeUserPassword("user", "12345");
Authorize MongoDB
- Start MongoDB without authentication.
- After that, connect to the server using the mongo shell.
- Create a user administrator.
- Enable authentication in the MongoDB configuration file.
- Now connect and authenticate as user admin.
- Finally, create additional users as needed.
Finding Passwords in MongoDB
You can specify the password directly as you did with earlier versions of the mongo shell. A user document contains a username and password and, optionally, an authentication mechanism and a digest password flag.
A user name and password that has access to the given database.
For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.
Related Articles
$ne operator in MongoDB
Publish Date:2025/04/11 Views:84 Category:MongoDB
-
This article will discuss how the $ne operator works in MongoDB. In addition, we will list its differences from the $not operator. $ne operator in MongoDB $ne is an operator in MongoDB that stands for not equal to. This will compare the val
MongoDB $Set Operator
Publish Date:2025/04/11 Views:159 Category:MongoDB
-
With the help of this article, you will learn how to use $set the operator to partially update objects in MongoDB so that the new object overlaps/merges with the existing object. The $set operator replaces the value of a field with a given
Difference between $push and $addToSet in MongoDB
Publish Date:2025/04/11 Views:63 Category:MongoDB
-
This article explains the operators in MongoDB. What is the purpose of $push and $addToSet operators. Furthermore, the difference between these two operators is given in the code snippet. This article discusses the following topics. Operato
Sort a collection by date in MongoDB
Publish Date:2025/04/11 Views:64 Category:MongoDB
-
In this MongoDB tutorial, the problem of sorting a collection in MongoDB is discussed. The different ways to sort a collection in the database are briefly explained. Using sort() function in MongoDB This problem is solved using the MongoDB
Counting records in MongoDB
Publish Date:2025/04/11 Views:146 Category:MongoDB
-
This article discusses operators in MongoDB, aggregation operators, and different ways to calculate the total number of records. Operations in MongoDB CRUD operations are a user interface concept that allows users to browse, search, and cha
Pretty printing in MongoDB
Publish Date:2025/04/11 Views:150 Category:MongoDB
-
This article will discuss how to use pretty printing in MongoDB to display formatted results. Pretty printing in MongoDB A cursor is an object that allows programmers in the Mongo world to iterate over documents in a Mongo collection. Altho
MongoDB Adding Elements to an Array
Publish Date:2025/04/11 Views:136 Category:MongoDB
-
This article will cover the various ways to add to an array in MongoDB. Adding to an array in MongoDB Use the $push operator to add values to an array The $push operator is one of the various array update operators provided by MongoDB
MongoDB Search by ID
Publish Date:2025/04/11 Views:131 Category:MongoDB
-
The following article provides an overview of MongoDB find by Id() method. MongoDB provides a find by Id() function which can retrieve documents matching a user id. To use search by Id() in MongoDB, you need to use the find() function. If n
MongoDB starts with a query
Publish Date:2025/04/10 Views:195 Category:MongoDB
-
In this MongoDB article, users will learn how to start queries using $regex. It provides regular expression functionality for pattern matching strings in queries. MongoDB starts querying using $regex If you want to use $regex , use one of t