MongoDB is fast and can handle large amounts of structured and unstructured data, making it a database of choice for web applications. The Spring framework provides powerful connectors to easily perform database operations with MongoDB. Data is stored as BSON objects in MongoDB making data retrieval easy.
For this Spring Boot and MongoDB example tutorial, we are only concerned with the Persistence and Database layers. We want to keep the focus on CRUD operations, so we will run our program from an Integrated Development Environment (IDE). We will add Spring Boot MongoDB configurations to connect Spring Boot and MongoDB.
- Java 17
- Spring Boot 2.7.4
- Gradle 7.5.1
- Cloud MongoDB
- Swagger UI
- Intellij Idea
- Input data validation
- Generic Exception Handler
- Custom Exception
- Swagger UI Api Documentation
- Custom Annotation for Validation
- Model Mapper(Object Mapper)
git clone https://github.com/codeprismtechnologies/starter-rest-api-mongodb-springboot.git
Step : 1
If you want to set up your own cloud mongoDB please refer this link: https://www.mongodb.com/basics/mongodb-atlas-tutorial
Step : 2
- Make sure you are using Java version 17
- Make sure your MongoDB server up and running
- Make sure using gradle version using 7+
- After cloning project. Refresh gradle once.
- Run project as springboot application
- To start testing rest api calls just copy below url paste it any browser Safari/Chrome/Mozilla..etc
http://localhost:8080/swagger-ui/
- Postman
- Insomnia
- SoapUI..etc