Clone wiki

server / MongoDB - Create root user

To create MongoDB root user do theese steps:

  1. Stop MongoDB server
  2. Make sure authentication is disabled, by creating mongod.cnf file in data directory with content:

    noauth = false
    
  3. Start MongoDB server

  4. Create root user by executing mongo commands:

    use admin
    db.createUser({
        user : "testing", 
        pwd : "testing",
        roles : [{role: "root", db: "admin"}]
    })
    
  5. Stop MongoDB server

  6. Enable authentication by setting content of mongod.cnf file to:

    noauth = true
    
  7. Start MongoDB server

  8. Try to connect with new user, if something goes wrong go to step 1.

Updated