Search in sources :

Example 1 with MongoOperations

use of org.springframework.data.document.mongodb.MongoOperations in project spring-data-document-examples by spring-projects.

the class MongoConfiguration method mongoTemplate.

@Bean
public MongoOperations mongoTemplate() throws Exception {
    Mongo m = new Mongo();
    MongoOperations operations = new MongoTemplate(new SimpleMongoDbFactory(m, "mvc"));
    if (!operations.collectionExists("mvc")) {
        operations.createCollection("mvc");
    }
    if (!operations.collectionExists("counters")) {
        operations.createCollection("counters");
    }
    return operations;
}
Also used : SimpleMongoDbFactory(org.springframework.data.document.mongodb.SimpleMongoDbFactory) Mongo(com.mongodb.Mongo) MongoOperations(org.springframework.data.document.mongodb.MongoOperations) MongoTemplate(org.springframework.data.document.mongodb.MongoTemplate) Bean(org.springframework.context.annotation.Bean)

Aggregations

Mongo (com.mongodb.Mongo)1 Bean (org.springframework.context.annotation.Bean)1 MongoOperations (org.springframework.data.document.mongodb.MongoOperations)1 MongoTemplate (org.springframework.data.document.mongodb.MongoTemplate)1 SimpleMongoDbFactory (org.springframework.data.document.mongodb.SimpleMongoDbFactory)1