mogodb 设置用户名密码认证:
#step 1: create account 1. mongo; 2. use admin; 3. db.createUser({ user: "root", pwd: "root", roles: [{ role: "userAdminAnyDatabase", db: "admin" }] }); 4. db.auth("root", "root"); #step2: set authenticate /etc/mongod.conf auth = true (uncomment it if it's comment) #step3: restart again sudo service mongod restart
#step4. check connect : --host localhost mongo --port 27017 -u"root" --authenticationDatabase "admin" -p"root"
use EDI_Monitor_Platform db.createUser({ user: "mongodbuser", pwd: "root", roles: [{ role: "dbOwner", db: "EDI_Monitor_Platform" }] }) db.grantRolesToUser("mongodb",[{role:"dbOwner",db:"EDI_Monitor_Platform"}])