如何在springboot连接到本地docker中运行的mongodb
About MongoDb roles
all roles:
Read: allow the user read the specified databaseConnect to a specified database in service
readWrite: allow the user to write data to specified database
dbAdmin: allow the user to exec management command,like create/delete index, check statistic, check system.profile
userAdmin: allow user insert data into system.users
dbOwner: owner of database, include readWrite、dbAdmin、userAdmin
clusterAdmin: only used in admin, allow the user copy or shard the database
readAnyDatabase: only used in admin, allow the user read all database
readWriteAnyDatabase: only used in admin, allow the user write to all database
userAdminAnyDatabase: only used in admin, give all userAdmin's authorities to user
dbAdminAnyDatabase: only used in admin, give all dbAdmin's authorities to user
root: only used in admin. super user, super authorities
1.start a database service in local host with docker
1.1 first you should run this in command 'docker run -p 27017:27017 -v $PWD/db:/data/db -d mongo' to start a mongodb service2.config properties (in this project I use yml)
1.2 then you should run this 'docker run -it mongo mongo --host 172.17.0.1' to connect to the service which started in step 1
host: localhost3.authentication
port: 27017
database: test you can connect to the local mongoDB service after configing this 3 properties
3.1 use 'db.createUser()' method to add a user to the specified database(remember to switch to the database with command 'use database-name'')
3.2 enable authentication with command 'mongod --auth'
3.3 use 'db.stopServer()' to stop service
3.4 restart the mongodb service with 'run -p 27017:27017 -v $PWD/db:/data/db -d mongo --auth'
3.5 and now if you want to do something in database you should auth(db.auth('username','password')) firstly and have the rights
【如何在springboot连接到本地docker中运行的mongodb】 3.6 then you should config another 2 properties (username , password)
推荐阅读
- 任时光绽放成六月繁花
- 我从来不做坏事
- 考研英语阅读终极解决方案——阅读理解如何巧拿高分
- 樱花雨
- 如何寻找情感问答App的分析切入点
- Activiti(一)SpringBoot2集成Activiti6
- 拍照一年啦,如果你想了解我,那就请先看看这篇文章
- mybatisplus如何在xml的连表查询中使用queryWrapper
- MybatisPlus使用queryWrapper如何实现复杂查询
- 人如果没梦想,和咸鱼有什么区别(自媒体时代把握住就能咸鱼翻身)