Skip to content

Instantly share code, notes, and snippets.

@whomwah
Last active March 18, 2020 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whomwah/d30238463408a78c02393f1122569d16 to your computer and use it in GitHub Desktop.
Save whomwah/d30238463408a78c02393f1122569d16 to your computer and use it in GitHub Desktop.
[MongoDB] #mongodb

Setup

https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-18-04

Permissions

https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-mongodb-on-ubuntu-16-04#part-two-securing-mongodb

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"
		}
	]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment