mongodb study notes 3

windows open User Authentication

Open the configuration file C: \ Program Files \ MongoDB \ Server \ 4.0 \ bin \ mongod.cfg

Add the following

security:
  authorization: enabled

Create a user

db.createUser({user:"admin",pwd:"admin",roles:["userAdminAnyDatabase"]}) 

 

Modify user permissions

Log mongdb, execute the following command

use admin
db.grantRolesToUser( 
"admin", 
["root"], 
{ w: "majority" , wtimeout: 5000 } 
)

grantRolesToUser function using the method described: https: //docs.mongodb.com/manual/reference/method/db.grantRolesToUser/#db.grantRolesToUser

Guess you like

Origin www.cnblogs.com/beilong/p/11521371.html