0

I'm rather new with MongoDB and I'm trying to add a admin account into my MongoDB whithout any users at this point. Using this command: mongo --port 27017 -u manager -p 123456 --authenticationDatabase admin

I receive this error: enter image description here

Kind regards.

Maxim
  • 97
  • 1
  • 9
  • 1
    duplicate thus adding earlier resolution thread reference here http://stackoverflow.com/questions/18216712/cannot-authenticate-into-mongo-auth-fails – Anvesh Kumar May 25 '16 at 14:14
  • @AnveshKumar I've tried all the solutions, none seem to work. I always get the same error. – Maxim May 26 '16 at 08:37

1 Answers1

0

Let me explain the reason why its not working. mongo db refers to users collection to validate the login user.

By default mongodb doesnt provide any user login like manager, using which your were trying to login

Thus the below command is not working

mongo --port 27017 -u manager -p 123456 --authenticationDatabase admin

To make the below command to work. You need to add user "manager" to mongodb user collection.

To create user run the below command:

db.addUser( { user: "manager",
          pwd: "123456",
          roles: [ "userAdminAnyDatabase",
                   "dbAdminAnyDatabase",
                   "readWriteAnyDatabase"

] } )

Once you have the user created, below command work.

mongo --port 27017 -u manager -p 123456 --authenticationDatabase admin