1、Connect to the server using the mongo shell

mongo mongodb://localhost:27017

  

2、Create the user administrator

Change to the admin database:

use admin

  

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

  

执行成功显示如下提示:

Enable Authentication on MongoDB

 

Then disconnect from the mongo shell (Ctrl+D)

3、Enable authentication in mongod configuration file

 编辑mongodb 配置文件:

sudo vim /etc/mongod.conf

  

在 # security: 节点下输入以下内容:

security:
  authorization: "enabled"

  

Enable Authentication on MongoDB

4、save the file and restart mongod :

sudo service mongod restart

  

5、 Connect and authenticate as the user administrator

mongo mongodb://localhost:27017

 

use admin

  

db.auth("Admin", "Admin123")

  

6、Finally, create additional users as needed

use BIMDB
db.createUser(
  {
    user: "myTester",
    pwd: "xyz123",
    roles: [ { role: "readWrite", db: "BIMDB" } ]
  }
)

 

7、use auth on appsetting.json

mongodb://myTester:xyz123@10.100.150.99:27017/BIMDB

  

 

相关文章:

  • 2022-12-23
  • 2021-04-15
  • 2022-12-23
  • 2021-09-13
  • 2021-11-29
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-05
  • 2022-02-10
  • 2021-11-20
  • 2021-12-01
  • 2021-09-03
相关资源
相似解决方案