MongoDB-Use --auth parameter with connecting error

时间:2021-07-17 12:10:14

When you use mongoDB started as "mongod --dbpath ../../data/db --auth", and you use the existed use in your database, but you will get error like this "purchase_user@purchase failed. MongoDB-CR Authentication failed. Missing credentials in user document when I access webservice through browser."

How to deal with this problem?

Go to mongoDB shell and delete your current user & set authSchema version 3 to instead of 5, follow these commands in mongo shell:

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

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

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