{"size": 1498, "ext": "js", "max_stars_repo_path": "initializeusers.js", "max_stars_repo_name": "jayproulx/aem-mongodb-prod-setup", "max_stars_repo_stars_event_min_datetime": "2017-02-14T15:46:02.000Z", "max_stars_repo_stars_event_max_datetime": "2017-02-14T15:46:02.000Z", "max_issues_repo_path": "initializeusers.js", "max_issues_repo_name": "jayproulx/aem-mongodb-prod-setup", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "initializeusers.js", "max_forks_repo_name": "jayproulx/aem-mongodb-prod-setup", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.75, "max_line_length": 134, "alphanum_fraction": 0.5961281709}
/**
 * Created by jproulx on 5/10/16.
 */

var siteroot = {
        user: 'siteroot',
        pwd: 'password',
        roles: [
            {
                role: 'root',
                db: 'admin'
            }
        ]
    };

var versionAdmin = {
        role: 'versionAdmin',
        privileges: [
            {
                resource: {db:'admin', collection: 'system.version'},
                actions: ['insert', 'update', 'find']
            }
        ],
        roles: []
    };

// In the admin database
// use admin

// Create root level user
db.createUser(siteroot);
db.auth(siteroot.user, siteroot.pwd);

// Create versionAdmin role
db.createRole(versionAdmin);

siteroot.roles.push({role: 'versionAdmin', db: 'admin'});

// Give versionAdmin to siteroot user
db.updateUser(siteroot.user, {roles: siteroot.roles});

// Make sure authSchema is version 3 MongoDB-CR authentication schema, it might be 5
db.system.version.find();

// {“_id”: “authSchema”, “currentVersion”: 5}
db.system.version.update({_id: 'authSchema'}, {$set:  {currentVersion: 3}}, upsert=true);
db.system.version.find();

// Create userAdmin user
db.createUser({user: 'userAdmin', pwd: 'password', roles: [{role: 'userAdminAnyDatabase', db: 'admin'}]});

// Create author user
db.createUser({user: 'author', pwd: 'password', roles: [{role: 'readWrite', db: 'aem-author'}, {role: 'dbOwner', db: 'aem-author'}]});

// Shut down mongod instance
// mongo admin -p -u site root —eval “printjson(db.shutdownServer())”