MongoDB on CentOS 6.6 – Cannot create admin

mongodb

I have a fresh install of CentOS 6.6 and installed MongoDB 3.0.6 as per the instructions here. https://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/

I am unable to create the admin user.

db.createUser({user:"admin",pwd:"mysecret", roles:[{role:"root",db:"admin"}]})

I get this error

Error: couldn't add user: not authorized on admin to execute command { createUser: "admin", pwd: "xxx", roles: [ { role: "root", db: "admin" } ], digestPassword: false, writeConcern: { w: "majority", wtimeout: 30000.0 } }
    at Error (<anonymous>)
    at DB.createUser (src/mongo/shell/db.js:1101:11)
    at (shell):1:4 at src/mongo/shell/db.js:1101

/etc/mongod.conf still has the lines to start mongod with the local exception:

 # Turn on/off security.  Off is currently the default
  #noauth=true
  #auth=true

I have also tried to create the admin user with userAdmin and userAdminAnyDatabase roles but I get the same errors.

the server has an error message "errmsg" : "not authorized on admin to execute command { serverStatus: 1 }"
Server status is Code 13.

I am running out of ideas…

Best Answer

It worked for me on CentOS 6.7 + MongoDB 3.0.6

Did you try to increase the log level ?

db.setLogLevel(3);

Also just to check, what does the following request return ?

db.system.users.find()