MongoDB AuthenticationFailed with MONGODB-CR mechanism

I 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 correctly authenticated from my localhost, but when I try to use an external client to connect 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 to fix it?

+3


source to share


2 answers


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

You need to delete the created user and 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.

+7


source


My symptom is different from the above question, but I am writing here for reference.
I am getting an on-premises authentication error.
This happens for me when I use a match match between a server and a mongodb client.
For example:

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


When I access the server using mongo with a valid user and password, it crashes due to a version mismatch.

+2


source







All Articles