mongodb add user
use <your database>
db.createUser({
user: '<some username>',
pwd: passwordPrompt(),
roles: [{
role: 'readWrite',
db: '<your database>'
}]
})
mongodb add user
use <your database>
db.createUser({
user: '<some username>',
pwd: passwordPrompt(),
roles: [{
role: 'readWrite',
db: '<your database>'
}]
})
connect to mongodb with username and password
->First run mongoDB on terminal using
mongod
->now run mongo shell use following commands
use admin
db.createUser(
{
user: "myUserAdmin",
pwd: "abc123",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
->Re-start the MongoDB instance with access control.
mongod --auth
->Now authenticate yourself from the command line using
mongo --port 27017 -u "myUserAdmin" -p "abc123" --authenticationDatabase "admin"
->You can read it from
https://docs.mongodb.com/manual/tutorial/enable-authentication/
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us