### 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: "" }, { role: "dbAdmin", db: "" } ] }) ```