通过shell创建用户
#!/bin/bash
DB_NAME=mydb
DB_USER=mydb
DB_PASSWORD=psw123
MONGO_ADMIN_USER=root
MONGO_ADMIN_PASSWORD=pwd123
MONGO_HOST=192.168.1.3:27017
MONGO_CMD="db.createUser({user: '${DB_USER}',pwd: '${DB_PASSWORD}',roles: [{role: 'dbOwner', db: '${DB_NAME}'}]});"
mongo mongodb://${MONGO_ADMIN_USER}:${MONGO_ADMIN_PASSWORD}@${MONGO_HOST}/${DB_NAME}?authSource=admin --quiet --eval "${MONGO_CMD}"
docker run --rm -it mongo:4.4 mongo mongodb://${MONGO_ADMIN_USER}:${MONGO_ADMIN_PASSWORD}@${MONGO_HOST}/${DB_NAME}?authSource=admin --quiet --eval "${MONGO_CMD}"
作者
jnan77
发表于
2022-05-20 14:20:41
,添加在分类
数据库
下
,并被添加「
mongodb
」标签
,最后修改于
2022-05-20 14:20:59
Comments