How to use SpringData MongoRepository to interact with MongoDB
How to use SpringData MongoRepository to interact with MongoDB
In the past post, we had learned how to work with MongoDB by MongoOperations which supports a set of standard APIs to manipulate data. So in the tutorial, JavaSampleApproach will show a powerful tool SpringData MongoRepository with flexible and more complex APIs to interact with MongoDB.
Related articles:
- Spring MongoOperations to access MongoDB
- How to build SpringBoot MongoDb RestfulApi
- SpringData MongoDB GridFsTemplate to save, retrieve, delete binary files (Image, Text files)
- Angular 4 + Spring Boot + MongoDB CRUD example
- Spring Boot + Angular 6 example | Spring Data + REST + MongoDb CRUD example
I. Technologies
– Java: 1.8
– Maven: 3.3.9
– Spring Tool Suite: Version 3.8.4.RELEASE
– Spring Boot: 1.5.4.RELEASE
- MongoDB: v3.4.1
I. MongoRepository
MongoRepository is implemented with lots of APIs to store and retrieve data. We can use MongoRepository with full generic CRUD operations of CrudRepository interface, and additional methods of PagingAndSortingRepository interface for pagination and sorting. MongoRepository also extends QueryByExampleExecutor so it allows execution of Query by Example.
public interface MongoRepository
extends PagingAndSortingRepository, QueryByExampleExecutor {
...
public interface PagingAndSortingRepository extends CrudRepository {
-> With a strong set of APIs, We should start Spring MongoRepository to manipulate data from MongoDB.
II. Practice
More at:
Top comments (0)