1. Start Mongo
docker run \
--name mongo \
--privileged=true \
--net network-common \
-v /elf/mongo/data:/data/db \
-p 27017:27017 -p 28017:28017 \
-e MONGODB_INITDB_ROOT_USERNAME=admin \
-e MONGODB_INITDB_ROOT_PASSWORD=mongo \
-e MONGODB_INITDB_DATABASE=mongo \
-itd mongo:7.0.5 --auth
--wiredTigerCacheSizeGB 1.5
--authenticationDatabase admin
-v /elf/mongo/etc/:/etc/mongo \
--config /elf/mongo/etc/mongod.conf
2. Mongo Grant
docker logs mongo
# mongodb://192.168.0.123:27017
# docker exec -it mongo /bin/bash
# mongosh 192.168.0.123:27017
docker exec -it mongo /bin/mongosh
use admin
# root,userAdminAnyDatabase
db.createUser({
user: "elf",
pwd: "mongo",
roles: [{ role: "root", db: "admin" }]
})
# userName - cipherCode
db.auth("elf", "mongo")
3. Mongo Client
-
Mongo Compass,Mongo Express,Robo 3T,Studio 3T,Navicat;
-
192.168.0.123:27017:elf - mongo
-
docker stop mongo && docker rm mongo && rm -rf mongo/
4. Role Privilege
Privilege | Memo |
---|---|
read |
允许用户读取指定数据库 |
readWrite |
允许用户读写指定数据库 |
dbAdmin |
允许用户在指定数据库中执行管理函数, |
dbOwner |
允许用户在指定数据库中执行任意操作,增、删、改、查等 |
clusterAdmin |
仅在admin库可用,赋予用户所有分片和复制集相关函数的管理权限 |
readAnyDatabase |
仅在admin库可用,赋予用户所有数据库的读权限 |
readWriteAnyDatabase |
仅在admin库可用,赋予用户所有数据库的读权限 |
userAdminAnyDatabase |
仅在admin库可用,赋予用户所有数据库userAdmin权限 |
dbAdminAnyDatabase |
仅在admin库可用,赋予用户所有数据库dbAdmin权限 |
root |
只在admin数据库中可用。超级管理员用户,超级权限 |
Role | Privilege |
---|---|
数据库用户角色 |
read、readWrite; |
数据库管理角色 |
dbAdmin、dbOwner、userAdmin; |
集群管理角色 |
clusterAdmin、clusterManager、 |
备份恢复角色 |
backup、restore |
所有数据库角色 |
readAnyDatabase、readWriteAnyDatabase、 |
超级用户角色 |
root |
Method | Url | Action |
---|---|---|
POST |
/api/tutorial |
create new Tutorial |
GET |
/api/tutorial |
retrieve all Tutorial |
GET |
/api/tutorials/:id |
retrieve Tutorial by :id |
PUT |
/api/tutorials/:id |
update Tutorial by :id |
DELETE |
/api/tutorial/:id |
delete Tutorial by :id |
DELETE |
/api/tutorial |
delete all Tutorial |
GET |
/api/tutorials/publish |
find all publish Tutorial |
GET |
/api/tutorials?title=[keyword] |
find all Tutorial which title contain keyword |