MongoDB-CR Authentication failed

I am getting following error while authenticating user : purchase_user@purchase failed. MongoDB-CR Authentication failed. Missing credentials in user document when I access webservice through browser.

But I am able to authenticate purchase_user from mongo it returns 1 .


Solution 1:

go to mongoDB console and delete your current user & set authSchema version to 3 instead of 5 , follow these commands in mongo console -

mongo
use admin
db.system.users.remove({})    <== removing all users
db.system.version.remove({}) <== removing current version 
db.system.version.insert({ "_id" : "authSchema", "currentVersion" : 3 })

Now restart the mongod and create new user then it should work fine.

Note: use remove commands in test db only, if in production use update.

Authentication information for Kubernetes Helm Chart

If you delete the all users and authentication is enabled in the configuration (or --auth param which is set per default on the Kubernetes helm chart), it's not possible to access MongoDB any more. Its required to disable authentication, create a new user and then re-enable it.

On Kubernetes you need to edit the parameters and add --noauth as argument, since it's not the default there as on a classic installed MongoDB. Please see the CLI documentation for more information about --noauth and the corresponding --auth.

Solution 2:

Had the same issue. What was happening to me was that when I use MongoDB 3 to create my user, it was using SCRAM-SHA-1 as it's authentication mechanism instead of MongoDB-CR. What I had to do was:

  1. List item
  2. Delete the created user.
  3. Modify the collection admin.system.version such that the authSchema's currentVersion is 3 instead of 5 (3 is using MongoDB-CR).
  4. Recreate your user.

Should work without problems now.

Solution 3:

The step number 2. above is not detailed explicitly, I found this solution and worked for me.

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