https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-18-04
Create admin user
$ mongo
>
> use admin
switched to db admin
> db.createUser(
... {
... user: "admin",
... pwd: "xxxadminpassordxxx",
... roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
... }
... )
Successfully added user: {
"user" : "admin",
"roles" : [
{
"role" : "userAdminAnyDatabase",
"db" : "admin"
}
]
}
Create jukebox user
root@mongo:~# mongo -u admin -p --authenticationDatabase admin
MongoDB shell version v4.2.3
Enter password:
connecting to: mongodb://127.0.0.1:27017/?authSource=admin&compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("564c11fd-d51a-46ca-8989-6eb79ada34a7") }
MongoDB server version: 4.2.3
> use jukebox
switched to db jukebox
> db.createUser(
... {
... user: "jb",
... pwd: passwordPrompt(),
... roles: [
... { role: "readWrite", db: "jukebox" }
... ]
... }
... )
Enter password:
Successfully added user: {
"user" : "jb",
"roles" : [
{
"role" : "readWrite",
"db" : "jukebox"
}
]
}