Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB AuthenticationFailed with mechanism MONGODB-CR

Tags:

mongodb

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?

like image 813
Ricky Avatar asked Dec 09 '22 03:12

Ricky


1 Answers

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.

like image 88
Kayvan Tehrani Avatar answered Dec 27 '22 03:12

Kayvan Tehrani