mongo localhost -u username -p pwd --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-1
db.createUser( { user: "username", pwd: "passwrd", roles: [ { role: "readWrite", db: "shujuku" }, } )
shell创建用户并登录
think that auth = true
is an invalid configuration and your mongod is not starting because of it. To enable authorization, try using the following instead:
security:
authorization: enabled
Then, to connect to the database, make sure that your client is using the correct authentication database and authentication mechanism. This can be done using the commmand line by the following command:
mongo localhost -u admin -p myAdminPass --authenticationDatabase admin --authenticationMechanism SCRAM-SHA-1