DEV Community

loizenai
loizenai

Posted on

How to use SpringData MongoRepository to interact with MongoDB

https://grokonez.com/spring-framework/spring-data/how-to-use-springdata-mongorepository-to-interact-with-mongdb-springboot-application

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:

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.

SpringData Mongodb - architectures c

II. Practice

More at:

https://grokonez.com/spring-framework/spring-data/how-to-use-springdata-mongorepository-to-interact-with-mongdb-springboot-application

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay