Introduction: Because the user management of MongoDB data is based on the management of a single library, his management strategy is probably as follows
If you verify the account of the Admin library, all libraries are accessible
If an account with a non-admin library is validated, this permission can only access the data under the current library
Suggested steps:
If you want to set the database account, it is best that we do not start the database validation, and then go to the Admin library, create a password
Exit Add -auth Verify restart MongoDB and then use the Admin library account to authenticate, if you go to another library for account creation, and then re-login after completion to verify
Verify the following:
Start Mongod
Mongod.exe--dbpath=e:\mongodb\db-auth -auth user authentication is turned on, user authentication will fail if startup does not add this parameter
First enter the Admin library
Use admin
Users viewing the current data
Show collections can return two tables
The SA account password for the Add Admin Library is SA
Db.adduser (' sa ', ' sa ')
CTRL + C exits the current login
Log back in and go to the Admin Library and test Library to check if you can query the current table
> Use adminswitched to DB admin> show Collectionsmon Oct 17:11:01 uncaught exception:error: {"$err": "U nauthorized db:admin lock Type:-1 client:127.0.0.1 "," code ": 10057}> use testswitched to DB admin> show Coll Ectionsmon Oct 17:13:51 uncaught exception:error: {"$err": "Unauthorized db:test lock type:-1 client:127.0.0. 1 "," Code ": 10057}
Verify that the SA account in the Admin Library is able to view information from the Admin Library and test Library
> Db.auth (' sa ', ' sa ') 1> show collectionssystem.indexessystem.users> use testswitched to DB test> show Collectionssystem.indexessystem.users>
Enter the test library and create the user test password test
> Use testswitched to DB test> db.adduser (' Test ', ' test ') {"updatedexisting": True, "n": 1, "C Onnectionid ": Ten," err ": null," OK ": 1}{" _id ": ObjectId (" 543b80be1d60b11044c2fc59 ")," use R ":" Test "," readOnly ": false," pwd ":" A6de521abefc2fed4f5876855a3484f5 "}>
CTRL + C Exit login again to verify that the test account has access to the test library and the admin library
> Db.auth (' Test ', ' Test ') 1> show collectionssystem.indexessystem.users> use adminswitched to DB admin> show Collectionsmon Oct 17:21:06 uncaught exception:error: {"$err": "Unauthorized db:admin lock Type:-1 client:127 .0.0.1 "," Code ": 10057}>
Verify the Admin admin account to see if you can view the Admin library information
> Use adminswitched to DB admin> db.auth (' sa ', ' sa ') 1> show collectionssystem.indexessystem.users>
PS: When authenticating a user, if return 1 proves to have this user, if return 0 proves that there is no such user as:
> Use adminswitched to DB admin> db.auth (' sa ', ' sa ') 1
This article is from the "Loyalty" blog, make sure to keep this source http://xinsir.blog.51cto.com/5038915/1563383
User Management for MongoDB