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