mongodb user authentication

The downloaded mongodb3.2.1 version encountered many problems when using the --auth parameter command line to enable mongodb user authentication. The summary is as follows: 

      (The ones found on Baidu are basically old versions. If you see db.addUser, please ignore.) 
After 3.0, mongodb added the SCRAM-SHA-1 verification method, which requires the cooperation of third-party tools for verification. The following is given Specific solution: 
first turn off authentication, modify the authSchema version in the system.version document to 3, and it should be 5 during the initial installation. The command line is as follows: 
> use admin 
switched to db admin 
> var schema = db.system.version.findOne( {"_id" : "authSchema"}) 
> schema.currentVersion = 3 

> db.system.version.save(schema) 
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) 

The reason is that the originally created user has already used the SCRAM-SHA-1 authentication method 
> use admin 
switched to db admin 
> db.system.users.find() 
[...] 
{ "_id" : "test.zxx", " user" : "zxx", "db" : "test", "credentials" : { " SCRAM-SHA-1 " : { "iterationCount" : 10000, "salt" : "XXXXXXXXXXXXXXXXXXXXXXXX", "storedKey" : "XXXXXXXXXXXXXXXXXXXXXXXXXXX", "serverKey" : "XXXXXXXXXXXXXXXXXXXXXXXXXXX" } }, "roles" : [ { "role" : "dbOwner", " db" : "test" } ] } The 

solution is to delete the user you just created and rebuild it: 
> use userdb 
switched to db userdb 
> db.dropUser("zxx") 
true 
>db.createUser({user:'zxx ',pwd:'123456',roles:[{role:'dbOwner',db:'test'}]}) 
then close the server, enable authentication, restart the server, connect with robomongo, everything is OK 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326931015&siteId=291194637