Ricky
Ricky

Reputation: 295

MongoDB AuthenticationFailed with mechanism MONGODB-CR

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?

Upvotes: 4

Views: 9917

Answers (2)

Kayvan Tehrani
Kayvan Tehrani

Reputation: 3210

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.

Upvotes: 8

Hill
Hill

Reputation: 3717

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.

Upvotes: 6

Related Questions