use of org.springframework.data.mongodb.core.QueryOperations.CountContext in project spring-data-mongodb by spring-projects.
the class MongoTemplate method count.
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.MongoOperations#count(org.springframework.data.mongodb.core.query.Query, java.lang.Class, java.lang.String)
*/
public long count(Query query, @Nullable Class<?> entityClass, String collectionName) {
Assert.notNull(query, "Query must not be null!");
Assert.hasText(collectionName, "Collection name must not be null or empty!");
CountContext countContext = queryOperations.countQueryContext(query);
CountOptions options = countContext.getCountOptions(entityClass);
Document mappedQuery = countContext.getMappedQuery(entityClass, mappingContext::getPersistentEntity);
return doCount(collectionName, mappedQuery, options);
}
use of org.springframework.data.mongodb.core.QueryOperations.CountContext in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplate method count.
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.ReactiveMongoOperations#count(org.springframework.data.mongodb.core.query.Query, java.lang.Class, java.lang.String)
*/
public Mono<Long> count(Query query, @Nullable Class<?> entityClass, String collectionName) {
Assert.notNull(query, "Query must not be null!");
Assert.hasText(collectionName, "Collection name must not be null or empty!");
return createMono(collectionName, collection -> {
CountContext countContext = queryOperations.countQueryContext(query);
CountOptions options = countContext.getCountOptions(entityClass);
Document filter = countContext.getMappedQuery(entityClass, mappingContext::getPersistentEntity);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Executing count: %s in collection: %s", serializeToJsonSafely(filter), collectionName));
}
return doCount(collectionName, filter, options);
});
}
Aggregations