MongoDB-Use --auth parameter with connecting error

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" : 3 })

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.

posted @ 2017-11-23 10:13  Baude_Lee  阅读(189)  评论(0编辑  收藏  举报