Example usage for org.springframework.data.mongodb.core MongoTemplate count

List of usage examples for org.springframework.data.mongodb.core MongoTemplate count

Introduction

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

Prototype

@Override
    public long count(final Query query, String collectionName) 

Source Link

Usage

From source file:com.seajas.search.profiler.service.repository.RepositoryService.java

/**
 * Default constructor./*from   w  ww  .  j a  v a  2s . c om*/
 *
 * @param dbFactory
 */
@Autowired
public RepositoryService(final MongoDbFactory dbFactory, final MongoTemplate mongoTemplate) {
    this.gridFs = new GridFS(dbFactory.getDb());

    // Initialize the indexes only if there aren't too many documents in the store yet

    Long currentCount = mongoTemplate.count(new Query(), CompositeEntry.class);

    // Determine whether the given indexes have been created, and initialize them if necessary

    if (currentCount <= MAX_INDEX_CREATION_COUNT)
        for (String index : INDEXES)
            mongoTemplate.indexOps(CompositeEntry.class).ensureIndex(new Index().on(index, Order.ASCENDING));

    this.mongoTemplate = mongoTemplate;
}