Spring boot MongoDB crud example
What you will learn here about MongoDB
- Spring boot MongoDB crud example
Please visit following link to know how to install MongoDB on windows
How to install MongoDB on windows
Spring boot MongoDB crud example
Please follow the following steps to know how to perform CURD operation with MongoDB using Spring boot
1)First open your MongoDB compass and Create Database and collection i.e table or document name which is shown below
2)Please create simple maven project
3)Please add MongoDB and spring starter web dependency in your pom.xml which is shown below
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-mongodb</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
4)Please add following properties in your application.properties which is shown below
spring.data.mongodb.host=localhost spring.data.mongodb.port=27017 spring.data.mongodb.database=Test
5)Create Document (entity or table) which is shown below
6)Create MongoRepository for document which is shown below
7)Create rest controller for perform different operations which is shown below
8)Now please run your spring boot application
9)Create Post request for adding student which is shown below
10)Create get request for getting all student which is shown below