1, MongoDB installed after the first entry is not required password, and no user, through the shell command can directly enter, CD to the MongoDB Directory Bin folder, execute the command./mongo can be run as follows:
[ [email protected] MongoDB Span style= "COLOR: #ff0000" >] #. / bin/ Mongomongodb Shell version: 1.8 . 2 connecting to : Test > use test;switched to DB test
 2, add Admin user (MongoDB does not have invincible user root, only can manage user's user useradminanydatabase), >use admin>db.createuser ( {user: " Admin ", pwd:" 123456 ", roles: [{role:" Useradminanydatabase ", DB:" Admin "}]}) Note: You can use show when you have finished adding users When users or Db.system.users.find () view existing user 3, add admin users, turn off MongoDB, and use permission mode to open MongoDB again, note that you should not use Kill to kill the MongoDB process directly. (If you do, go to the data/db directory to delete the Mongo.lock file), you can use Db.shutdownserver () to turn off 4, use permissions to start Mongodb./mongod--dbpath=/usr/ Local/mongodb/data--logpath=/usr/local//mongodb/mongod.log--fork --auth or modified in config file: auth = True#noauth = True 5, enter the MONGO shell, use the admin database and verify, if not verified, can not do any operation. > use admin> db.auth ("admin", "123456") #认证, returns 1 for successful 6, after validation, or not, because admin only has user administrative rights, create user below, The user follows the vault,> use mydb> db.createuser ({User: "root", pwd: "123456", roles: [{role: "ReadWrite", DB: "MyDB"}]}) 7, make Database operation with user root login created: [[email protected] mongodb]# MONGO 127.0.0.1/mydb-uroot-pmongodb Shell Version:3.2.9enter Password:connecting to:127.0.0.1/mydb> dbmydb> Use mydbswitched to DB mydb> show collections then you can do a variety of data manipulation ...
MongoDB user authorization and administration