In this blog, We are going to explore and learn the Spring Boot application with MongoDB Atlas. For that, we need to first need to create an account at https://cloud.mongodb.com, and configure some default settings in order to spin a new free cluster. We also get the option to select the cloud provider and region.
after creating the cluster and configuring credentials, we are all set as you can see I have created a new cluster in the AWS cloud, and the Collection is called "task" and it is a shared one so free no charges will apply.
Next, let's initialize the Spring Boot application for that, we can go to https://start.spring.io/ or if you have a Spring Boot plugin in your IDE you can use that as well.
In the Spring initializer, I have added four dependencies.- Spring Web:- For building RESTful APIs.
- Spring Data MongoDB: - It is a part of the Spring Data project, which provides integration with the MongoDB document database.
- Spring Boot Actuator:- it is a sub-project of Spring Boot and is used for monitoring purposes.
- Lombok:- For Java annotations.
- Create some content in MongoDB Atlast using Spring Boot API:
- Let's invoke the GET by ID endpoint
- GET ALL endpoint
- Rest of the operations you can check in the code but one more thing I wanted to show here is how the data is stored in the MongoDB Atlas, for that we can go to the cluster and click on Browse Collection