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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

please define productname in your docbook file!Here is an example that uses the CollectionCallback to return information about an indexboolean hasIndex = template.execute("geolocation", new CollectionCallbackBoolean>() {public Boolean doInCollection(Venue.class, DBCollection collection) throwsMongoException, <strong>Data</strong>AccessException {List indexes = collection.getIndexInfo();for (DBObject dbo : indexes) {if ("location_2d".equals(dbo.get("name"))) {return true;}}return false;}});5.16 GridFS support<strong>MongoDB</strong> supports storing binary files inside it's filesystem GridFS. <strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> providesa GridFsOperations interface as well as the according implementation GridFsTemplate toeasily interact with the filesystem. You can setup a GridFsTemplate instance by handing it aMongoDbFactory as well as a MongoConverter:class GridFsConfiguration extends AbstractMongoConfiguration {// … further configuration omitted}@Beanpublic GridFsTemplate gridFsTemplate() {return new GridFsTemplate(mongoDbFactory(), mappingMongoConverter());}Example 5.27 JavaConfig setup for a GridFsTemplateAn according XML configuration looks like this:Example 5.28 XML configuration for a GridFsTemplateYou can no get the template injected and perform storing and retrieving operations to it.1.4.0.BUILD-SNAPSHOT<strong>Spring</strong> <strong>Data</strong> <strong>MongoDB</strong> -Reference Documentation 67

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

Saved successfully!

Ooh no, something went wrong!