修改配置文件mongod.conf
Linux
配置文件路径,/etc/mongod.conf
net: port: 27017 - bindIp: 127.0.0.1 + bindIp: 0.0.0.0
# 密码登录 security: authorization: enabled
|
创建用户
> use admin switched to db admin
|
> db.createUser({ user: '??????', pwd: '123456', roles: [{role: 'userAdminAnyDatabase', db: 'admin'}], });
|
查看刚才创建的用户
重启数据库
mongod - f /etc/mongod.conf;
|
root@VM-4-9-debian:~# mongo 127.0.0.1/admin -u ?????? -p MongoDB shell version v4.2.6 Enter password: connecting to: mongodb: Implicit session: session { "id" : UUID("ee412fa7-b774-477e-b086-082da2c35335") } MongoDB server version: 4.2.6 > show dbs admin 0.000GB config 0.000GB local 0.000GB notebooks-alpha 0.000GB notebooks-production 0.000GB notebooks-staging 0.000GB
|