Example usage for org.springframework.data.mongodb.core.index CompoundIndexDefinition CompoundIndexDefinition

List of usage examples for org.springframework.data.mongodb.core.index CompoundIndexDefinition CompoundIndexDefinition

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core.index CompoundIndexDefinition CompoundIndexDefinition.

Prototype

public CompoundIndexDefinition(Document keys) 

Source Link

Document

Creates a new CompoundIndexDefinition for the given keys.

Usage

From source file:org.cbioportal.session_service.domain.internal.SessionRepositoryImpl.java

@Override
public void saveSession(Session session) {
    if (!this.mongoTemplate.collectionExists(session.getType())) {
        this.mongoTemplate.createCollection(session.getType());
        DBObject indexKeys = new BasicDBObject();
        indexKeys.put("source", 1);
        indexKeys.put("type", 1);
        indexKeys.put("checksum", 1);
        this.mongoTemplate.indexOps(session.getType())
                .ensureIndex(new CompoundIndexDefinition(indexKeys).unique());
    }/*from  www . j a v  a2s.c o m*/
    this.mongoTemplate.save(session, session.getType());
}