MongoDB support

The MongoDB support contains a wide range of features:

  • Spring configuration support with Java-based @Configuration classes or an XML namespace for a Mongo driver instance and replica sets.

  • MongoTemplate helper class that increases productivity when performing common Mongo operations. Includes integrated object mapping between documents and POJOs.

  • Exception translation into Spring’s portable Data Access Exception hierarchy.

  • Feature-rich Object Mapping integrated with Spring’s Conversion Service.

  • Annotation-based mapping metadata that is extensible to support other metadata formats.

  • Persistence and mapping lifecycle events.

  • Java-based Query, Criteria, and Update DSLs.

  • Automatic implementation of Repository interfaces, including support for custom finder methods.

  • QueryDSL integration to support type-safe queries.

  • Cross-store persistence support for JPA Entities with fields transparently persisted and retrieved with MongoDB (deprecated - to be removed without replacement).

  • GeoSpatial integration.

For most tasks, you should use MongoTemplate or the Repository support, which both leverage the rich mapping functionality. MongoTemplate is the place to look for accessing functionality such as incrementing counters or ad-hoc CRUD operations. MongoTemplate also provides callback methods so that it is easy for you to get the low-level API artifacts, such as com.mongodb.client.MongoDatabase, to communicate directly with MongoDB. The goal with naming conventions on various API artifacts is to copy those in the base MongoDB Java driver so you can easily map your existing knowledge onto the Spring APIs.