Querying with MongoOperations

So far, we have delved into the repository solution using both query by property and Query by Example. There is another angle we can use, MongoTemplate.

MongoTemplate mimics the Spring Framework's JdbcTemplate, the first data access mechanism implemented by Spring. JdbcTemplate allows us to focus on writing queries while delegating connection management and error handling to the framework.

MongoTemplate brings the same power to bear on crafting MongoDB operations. It's very powerful, but there is a critical tradeoff. All code written using MongoTemplate is MongoDB-specific. Porting solutions to another data store is very difficult. Hence, it's not recommended as the first solution, but as a tool to keep in our ...

Get Learning Spring Boot 2.0 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.