Skip to content

Instantly share code, notes, and snippets.

@SerhiiKozachenko
Created August 22, 2015 13:28
Show Gist options
  • Save SerhiiKozachenko/91363d4982fb45d6f46e to your computer and use it in GitHub Desktop.
Save SerhiiKozachenko/91363d4982fb45d6f46e to your computer and use it in GitHub Desktop.
MongoDB Guide
How to create root user
```
db.createUser({user: 'sa', pwd:'Serg1990SA', roles: ['root']})
Successfully added user: { "user" : "sa", "roles" : [ "root" ] }
```
Admin user
```
use admin
db.createUser(
{
user: "siteUserAdmin",
pwd: "password",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
}
)
```
MongoDB 3.0
If you can't connect to db with auth parameters:
The new auth schema were introduced with Mongo 3 SCRAM-SHA-1
and not all GUI tools are support it (for now only MongoChef),
The workaround is to force mongo use old (MongoDB-CR) auth schema and then recreate users
you can check that user has new auth schema by:
```
db.system.users.find({user: 'serg'}).pretty()
```
```
mongo
use admin
db.system.users.remove({}) <== removing all users
db.system.version.remove({}) <== removing current version
db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 })
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment