13.07.2015 Views

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

Spring Data MongoDB - Spring Web Services - Parent - SpringSource

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

please define productname in your docbook file!5.4 Introduction to MongoTemplateThe class MongoTemplate, located in the packageorg.springframework.data.document.mongodb, is the central class of the <strong>Spring</strong>'s <strong>MongoDB</strong>support providng a rich feature set to interact with the database. The template offers convenienceoperations to create, update, delete and query for <strong>MongoDB</strong> documents and provides a mappingbetween your domain objects and <strong>MongoDB</strong> documents.NoteOnce configured, MongoTemplate is thread-safe and can be reused across multiple instances.The mapping between <strong>MongoDB</strong> documents and domain classes is done by delegating toan implementation of the interface MongoConverter. <strong>Spring</strong> provides two implementations,SimpleMappingConverter and MongoMappingConverter, but you can also write your ownconverter. Please refer to the section on MongoCoverters for more detailed information.The MongoTemplate class implements the interface MongoOperations. In as much as possible,the methods on MongoOperations are named after methods available on the <strong>MongoDB</strong> driverCollection object as as to make the API familiar to existing <strong>MongoDB</strong> developers who are used tothe driver API. For example, you will find methods such as "find", "findAndModify", "findOne", "insert","remove", "save", "update" and "updateMulti". The design goal was to make it as easy as possible totransition between the use of the base <strong>MongoDB</strong> driver and MongoOperations. A major difference inbetween the two APIs is that MongOperations can be passed domain objects instead of DBObject andthere are fluent APIs for Query, Criteria, and Update operations instead of populating a DBObjectto specify the parameters for those operatiosn.1.4.0.BUILD-SNAPSHOT<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> -Reference Documentation 33

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!