This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Data MongoDB 4.4.0! |
MongoDB Support
Spring Data support for MongoDB 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.
-
Automatic implementation of Repository interfaces, including support for custom query methods.
-
QueryDSL integration to support type-safe queries.
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.