mongodb建用户

玛德折腾了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

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://uudwc.com/A/MxbXw

原文地址:https://blog.csdn.net/epmgy315/article/details/132531109

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请联系站长进行投诉反馈,一经查实,立即删除!

h
上一篇 2023年09月02日 02:21
下一篇 2023年09月02日 02:21