How to add authentication to
At first you need to create an admin user, so bring up a mongo shell by typing
Now by using
Disconnect the mongo shell.
The important note about mongo is to run it by
#mongodb #mongo #auth #authentication #create_user
MongoDB
?At first you need to create an admin user, so bring up a mongo shell by typing
mongo
in your terminal and hit enter. The database that users are stored is admin
, so switch to admin
database:use admin
Now by using
createUser
database method we will create a user called myUserAdmin
:db.createUser(
{
user: "myUserAdmin",
pwd: "1234qwer",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
Disconnect the mongo shell.
The important note about mongo is to run it by
--auth
argument, otherwise authentication would not work:mongod --auth --port 27017 --dbpath /data/db1
#mongodb #mongo #auth #authentication #create_user