typora/daliy_note/10.15/mongo.md
2024-12-12 10:48:55 +08:00

36 lines
646 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

### docker 部署mongoDB
```bash
docker run -itd -p 27017:27017 -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=123456 --name mongo mongo
```
### 用root用户登录
- 解决创建用户报错误问题
Command createUser requires authentication
```bash
docker exec -it mongo bash # 进入到容器的terminal
mongosh --username root --password --authenticationDatabase admin # 认证admin账户
```
### 给database创建用户
```bash
use cmdb
db.createUser({
user: "root",
pwd: "123456",
roles: [
{ role: "readWrite", db: "<database_name>" },
{ role: "dbAdmin", db: "<database_name>" }
]
})
```