O'Reilly logo

MongoDB for Java Developers by Francesco Marchioni

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using the Mongo template component to access MongoDB

Using the repository interface provides a convenient way to create applications using standard CRUD operations, which are prebuilt around the fields contained in the model. If you need fine grained control over your data, an alternative is to use MongoTemplate, which is located in the package org.springframework.data.document.mongodb.

The simplest way to use MongoTemplate is to wire the MongoOperations component in your code, which is the superinterface of MongoTemplate. This interface replicates the methods that are already available in the Mongo driver, thus making the transition simpler between the driver and MongoTemplate. For example, you can execute methods such as find, findOne, findAndModify ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required