liveBook · Manning

Spring Data MongoDB

As explained in Spring in Action, Sixth Edition

Spring Data MongoDB is a Spring Data project that provides repository-based persistence for Mongo document databases.

Spring Data MongoDB provides repository-based persistence for Mongo document databases. It uses domain-class annotations to map application objects to documents and repository interfaces that follow the familiar Spring Data programming model. section 4.2

A basic nonreactive setup involves these steps:

  • Add the Spring Data MongoDB starter, either directly to the build or through Spring Initializr. Spring Boot autoconfiguration then enables automatic repository support. section 4.2.1
  • Run MongoDB locally, commonly on port 27017, or use an embedded Flapdoodle database for development and testing. Embedded data disappears when the application restarts. section 4.2.1
  • Configure the production host, port, credentials, and database name when MongoDB is not running locally. section 4.2.1

Repository interfaces

A repository can extend CrudRepository without implementation code: IngredientRepository extends CrudRepository<Ingredient, String>, while OrderRepository extends CrudRepository<TacoOrder, String>. The String identifier reflects automatic ID assignment and differs from the identifier types used in other persistence technologies. section 4.2.3

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>
    spring-boot-starter-data-mongodb
  </artifactId>
</dependency>

Use the starter dependency to enable Spring Data MongoDB and its automatically created repository infrastructure. section 4.2.1

How Spring in Action, Sixth Edition covers it

How deep it goes
Explains setup, runtime choices, connection properties, domain mapping, and repository interfaces without detailing MongoDB internals.
Examples
Uses IngredientRepository, OrderRepository, Docker MongoDB, embedded Flapdoodle MongoDB, and production connection properties.
What it assumes
Assumes Spring Data repository familiarity while introducing MongoDB-specific setup, document mapping, and identifier choices.
What you can do after
Build repositories, configure MongoDB environments, and choose nonreactive or reactive persistence support.
How it connects
Connects domain classes, CrudRepository, Spring Boot autoconfiguration, MongoDB, Cassandra, JPA, and reactive persistence.

Also explained in

Compare how 2 books explain Spring Data MongoDB →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring in Action, Sixth Edition. The section links point to the parts of the book it draws on.