4

I've created these two users in my admin database:

db.auth('admin','password')
1
> db.getUsers()
[
    {
        "_id" : "admin.siteUserAdmin",
        "user" : "siteUserAdmin",
        "db" : "admin",
        "roles" : [
            {
                "role" : "userAdminAnyDatabase",
                "db" : "admin"
            }
        ]
    },
    {
        "_id" : "admin.admin",
        "user" : "admin",
        "db" : "admin",
        "roles" : [
            {
                "role" : "userAdminAnyDatabase",
                "db" : "admin"
            }
        ]
    }
]

I am uthenticated correctly from my localhost, but when I try to use an external client to get connected to my database I got this error:

Failed to authenticate admin@admin with mechanism MONGODB-CR: AuthenticationFailed MONGODB-CR credentials missing in the user document

How do I fix it?

Ricky
  • 285
  • 5
  • 17

2 Answers2

8

As stated here: MongoDB 3 authentication mechanism has been changed from MongoDB Challenge and Response (MONGODB-CR) to challenge and response mechanism (SCRAM-SHA-1).

You have to delete your created user then change admin.system.version.authSchema to 3 instead of 5. Then recreating your user should solve the problem:

var schema = db.system.version.findOne({"_id" : "authSchema"})
schema.currentVersion = 3
db.system.version.save(schema)

This link might be helpful too.

Kayvan Tehrani
  • 3,070
  • 2
  • 32
  • 46
6

My symptom is different from the above question but I am writing down here for reference.
I get an authentication error within local environment.
This happens for me when I use miss matching version between mongodb server and client.
For example:

  • Server: the version of mongod is v3.4.2.
  • Client: the version of mongo is 2.6.10.

When I access the server by mongo with valid user and password, it fails due to version miss-match.

Hill
  • 3,391
  • 3
  • 24
  • 28
  • Hey, it's a valid answer, indeed. Thanks! As a recommendation, I'd say that you should improve the text. Just a tip :)! – ivanleoncz Oct 11 '17 at 18:00