mongodbHow to enable authentication in MongoDB?
MongoDB supports several different methods for authentication.
The most basic authentication method is the MongoDB Native Authentication, which uses a username and password to authenticate a user.
To enable authentication in MongoDB, you need to create a user with the db.createUser()
method.
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
The above example creates a user with the username myUserAdmin
and the password abc123
, and assigns the userAdminAnyDatabase
role to the user.
Once the user is created, you can enable authentication in MongoDB by setting the auth
parameter to true
in the mongod.conf
configuration file.
Helpful links
More of Mongodb
- How to use unwind in MongoDB?
- How to remove a field from MongoDB?
- How to use MongoDB queue?
- How to create a many to many relation in MongoDB?
- How to use watch in MongoDB?
- How to use MongoDB query with "or" condition?
- How to perform a health check for MongoDB?
- How to check the version of MongoDB?
- How to update one document in MongoDB?
- How to update an array element in MongoDB?
See more codes...