First, when you start Mongo, you need to add a very heavy parameter. -- Auth with this parameter will enable severe permissions. Therefore, the owner is not responsible for permission verification by default.
#./Mongod -- dbpath/data/mongo_data/-- logpath/data/mongo_log/mongolog. log -- auth -- logappend &
-- Dbpath
Yesdata address, which can be customized-- Logpath
Is the log file address, which can be customized-- AuthPermission Verification-- LogappendAccumulate logs
After the startup is complete, you can now use the permission Link
#./Mongo database name-u username-P Password
Use Program You must add
DB. Authenticate (username, password. tochararray ());
String address = cfgmap. get ("Mongo. DB. address "); int Port = integer. parseint (partition map. get ("Mongo. DB. port "). tostring (); string dbname = cfgmap. get ("Mongo. DB. dbname "); string username = cfgmap. get ("Mongo. DB. username "); string Password = shortmap. get ("Mongo. DB. password "); Mongo = new Mongo (address, Port); If (dbname! = NULL &&! "". Equals (dbname) {DB = Mongo. getdb (dbname); If (username! = NULL &&! "". Equals (username) {// Authenticate identity dB. Authenticate (username, password. tochararray () ;}mongodbs. Put (dbname, DB );}