玛德折腾了2个小时,、mongodb 建用户。艹
[root@k8-master mongodb]# cat docker-compose.yaml
version: '2'
services:
mongodb:
container_name: mongodb_2.0
image: mongo:4.4
restart: always
environment:
TZ: 'Asia/Shanghai'
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: glr@cems135
MONGO_INITDB_DATABASE: geodata
MONGO_INITDB_USERNAME: cems
MONGO_INITDB_PASSWORD: glr@135!
volumes:
- "./data:/data/db"
- "/etc/localtime:/etc/localtime:ro"
- "./init-mongo.sh:/docker-entrypoint-initdb.d/init-mongo.sh"
ports:
- "27017:27017"
[root@k8-master mongodb]# docker-compose up -d
[root@k8-master mongodb]#docker exec -ti mongodb_2.0 /bin/bash文章来源:https://www.toymoban.com/news/detail-680522.html
root@bafbe3e610d2:/# mongo admin
MongoDB shell version v4.4.11
connecting to: mongodb://127.0.0.1:27017/admin?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("f5695822-4106-4642-9597-ef1a7239ca1c") }
MongoDB server version: 4.4.11
> db.auth('admin','glr@cems135') ;
1
>
>
> use geodata
switched to db geodata
>
> db.createUser({user:'cems',pwd:'glr@135!',roles:[{role:'userAdmin',db:'geodata'},"readWrite"]});
Successfully added user: {
"user" : "cems",
"roles" : [
{
"role" : "userAdmin",
"db" : "geodata"
},
"readWrite"
]
}
>文章来源地址https://www.toymoban.com/news/detail-680522.html
到了这里,关于mongodb建用户的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!