1. Install and configure password login
-
2. Create a super administrator user
use admin db.createUser({ user:'root', pwd:'root', roles:[{role:'root',db:'admin'}] }) # Successfully added user: { # "user" : "root", # "roles" : [ # { # "role" : "root", # "db" : "admin" # } # ] # }
-
3. Modify the configuration file
#mac电脑是:/usr/local/etc/mongod.conf # 1.先拷贝一份 cp mongod.conf mongod_bank.conf # 2.在mongod.conf中添加 security: authorization: enabled
-
4. Stop running
mongodb
use admin; db.shutdownServer();
-
5. Use commands to run in the background
mongodb
nohup mongod &
Two, create a separate password for the database
-
1. Create a secret order
use nest_cms db.createUser( { user: "nest_cms", pwd: "123456", roles: [ { role: "dbOwner", db: "eggcms" } ] })
-
2. [
mongodb
Built-in role](https://www.cnblogs.com/zzw1787044/p/5773178.html