Spring boot integrates Mongo to solve some common connection and permission problems. Docker compose installs Mongo
1、 Docker compose to install Mongo
version: '3.1'
services:
mongo:
image: mongo
container_name: mongo
restart: always
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: 123456
mongo-express:
image: mongo-express
container_name: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_SERVER: mongo
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: 123456
2、 Spring boot integrates Mongo
Maven dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
There are some points to pay attention to in the yaml configuration of springboot
1、 How to configure URI
1. Using the URI configuration method to configure password, user name, etc. will not take effect
2. If you encounter permission problems, check whether the user name and password match first. If you encounter
Command failed with error 17 (ProtocolError): ‘Attempt to switch database target during SASL authentication.
This kind of error report usually ends?Authsource = admin without
spring:
data:
mongodb:
uri: mongodb://root:[email protected]:27017/demo?authSource=admin
2、 Configuration of traditional SQL
1. If you are a pure digital password, for example, the author’s password is 123456, use single or double quotation marks when configuring, otherwise you will be identified incorrectly, because the receiving password uses char array, and 123456 will obviously overflow
spring:
data:
mongodb:
username: root
password: '123456'
host: 192.168.50.150
port: 27017
database: demo
authentication-database: admin
Read More:
- Error: could’t connect to server 127.0.0.1:27017 Src / Mongo / shell/ mongo.js
- Mongodb uses Mongo to report error: could’t connect to server 127.0.0.1:27017, connection attempt failed: socket
- Mongo connection remote address error
- Spring boot integrates es cluster error report collection
- Spring boot problem 1: error reporting life processing instructions for building a spring boot project
- mongo Failed to instantiate *** constructor NO_CONSTRUCTOR with arguments
- Solve the problem of docker error: Unsupported compose file version: 3.2
- Solve the problem of general error: 4047 when docker installs MariaDB of nextcloud
- Add PageHelper spring boot starter dependency to springboot and report an error
- Docker compose reports an error and multiple containers conflict
- Common command of docker
- Execution repackage of goal org.springframework.boot:spring-boot-maven-plugin:2.4.0:repackage failed
- Spring integrates JUnit configuration
- Solve the problem caused by: java.sql.SQLRecoverableException : IO error: connection reset related problems
- The spring boot project was first created, pom.xml The error is Maven configuration problem. How to solve it?
- docker-compose Error Traceback (most recent call last)
- [Solved] Docker Container Use APT error: Permission denied
- How to solve problems like curl: (7) failed to connect to raw.githubusercontent.com Port 443: problem with connection used
- In the XML configuration file of spring jdbc.properties The connection to the database failed due to garbled code
- Spring boot problem solving record (1)