MongoDB-CR Authentication failed

ashwini picture ashwini · Mar 12, 2015 · Viewed 47k times · Source

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 .

Answer

vivex picture vivex · Jul 17, 2015

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.