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" } ]
}
)

  

执行成功显示如下提示:

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"

  

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

  

最新文章

  1. SolrCloud-如何在.NET程序中使用
  2. Xcode7.x中安装Alcatraz
  3. 对Docker的价值和应用场景分析
  4. 开源 VS 商业,消息中间件你不知道的那些事
  5. php继承与重载
  6. Nape的回调系统 nape.callbacks
  7. String分割类
  8. c# 代码执行时间
  9. Spring学习之注入方式
  10. jQuery(二)
  11. CMD获取当前目录的绝对路径
  12. java模式:模板模式的简单理解
  13. bzoj2434阿狸的自动机
  14. EBS财务模块表结构
  15. iOS 波浪效果的实现
  16. shell测试命令test、[ ]、[[ ]]
  17. PHP获取网络图片并保存在本地目录
  18. 封装海康SDK出现无法加载 DLL“..\bin\HCNetSDK.dll”: 找不到指定的模块
  19. 笔记react router 4(一)
  20. Linux 安装redis,redis发布订阅,持久化

热门文章

  1. TestNG 四 测试方法之工厂
  2. IOS 开发学习33 使用sqlite3
  3. canvas贝济埃曲线
  4. 学 Vim 时希望早点知道的建议
  5. Navicat Premium如何打开SQL文件.MDF和.LDF文件
  6. JavaScript 中的string 方法
  7. 分析USB平台设备模型框架(1)
  8. 转发:【PHP】转义和过滤html单、双引号及HTML标签
  9. 【Shiro】Apache Shiro架构之集成web
  10. Nginx视频流模块nginx-rtmp-module