Show Topics
Hide Topics

Spring Boot MongoDB REST Example

 

Configuration file application.properties

 

we need to model our documents. Let’s call ours ‘Student’ and give it a make, model, and description. Here is our Java class to accomplish this.

  • @Id- id provided by Mongo for a document.
  • @Documentprovides a collection name.

 

 

StudentRepository.java

The MongoRepository provides basic CRUD operation methods and also an API to find all documents in the collection.

 

 

StudentController.java

 

SpringBootMongoDbApplication.java

 

http://localhost:8080/student/create?sno=101&name=Satya&address=HYDERABAD

Download Example