@Override @SuppressWarnings("deprecation") public long count(final ClientSession clientSession, final Bson filter) { return count(clientSession, filter, new CountOptions()); }
@Override @SuppressWarnings("deprecation") public long count(final Bson filter) { return count(filter, new CountOptions()); }
@Override public long countDocuments(final Bson filter) { return countDocuments(filter, new CountOptions()); }
@Override public long countDocuments(final ClientSession clientSession, final Bson filter) { return countDocuments(clientSession, filter, new CountOptions()); }
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!"); CountOptions options = new CountOptions(); query.getCollation().map(Collation::toMongoCollation).ifPresent(options::collation); Document document = queryMapper.getMappedObject(query.getQueryObject(), Optional.ofNullable(entityClass).map(it -> mappingContext.getPersistentEntity(entityClass))); return doCount(collectionName, document, options); }
@Override @SuppressWarnings("deprecation") public long count() { return count(new BsonDocument(), new CountOptions()); }
public static CountOptions fromEstimatedDocumentCountOptions(final EstimatedDocumentCountOptions options) { return new CountOptions().maxTime(options.getMaxTime(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS); }
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 -> { Document filter = query == null ? null : queryMapper.getMappedObject(query.getQueryObject(), entityClass == null ? null : mappingContext.getPersistentEntity(entityClass)); CountOptions options = new CountOptions(); if (query != null) { query.getCollation().map(Collation::toMongoCollation).ifPresent(options::collation); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing count: {} in collection: {}", serializeToJsonSafely(filter), collectionName); } return collection.count(filter, options); }); }
@Override public Mono<Long> count(Query query, @Nullable Class<?> entityClass, String collectionName) { if (!session.hasActiveTransaction()) { return super.count(query, entityClass, collectionName); } return createMono(collectionName, collection -> { Document filter = query == null ? null : delegate.queryMapper.getMappedObject(query.getQueryObject(), entityClass == null ? null : delegate.mappingContext.getPersistentEntity(entityClass)); CountOptions options = new CountOptions(); if (query != null) { query.getCollation().map(Collation::toMongoCollation).ifPresent(options::collation); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing count: {} in collection: {}", serializeToJsonSafely(filter), collectionName); } return collection.countDocuments(filter, options); }); } }
@Override public Boolean doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { return doCount(collection.getNamespace().getCollectionName(), mappedQuery, new CountOptions().limit(1).collation(collation)) > 0; } }
@Override public CountOptions convert(Environment env, TraceInfo trace, Memory arg) throws Throwable { if (arg.isNull()) return null; ArrayMemory arr = arg.toValue(ArrayMemory.class); CountOptions options = new CountOptions(); if (arr.containsKey("skip")) options.skip(arg.valueOfIndex("skip").toInteger()); if (arr.containsKey("limit")) options.limit(arg.valueOfIndex("limit").toInteger()); if (arr.containsKey("maxTime")) { options.maxTime(WrapTimer.parsePeriod(arg.valueOfIndex("maxTime").toString()), TimeUnit.MILLISECONDS); } return options; }
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!"); CountOptions options = new CountOptions(); query.getCollation().map(Collation::toMongoCollation).ifPresent(options::collation); Document document = queryMapper.getMappedObject(query.getQueryObject(), Optional.ofNullable(entityClass).map(it -> mappingContext.getPersistentEntity(entityClass))); return doCount(collectionName, document, options); }
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 -> { Document filter = query == null ? null : queryMapper.getMappedObject(query.getQueryObject(), entityClass == null ? null : mappingContext.getPersistentEntity(entityClass)); CountOptions options = new CountOptions(); if (query != null) { query.getCollation().map(Collation::toMongoCollation).ifPresent(options::collation); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing count: {} in collection: {}", serializeToJsonSafely(filter), collectionName); } return collection.count(filter, options); }); }
@Override public Mono<Long> count(Query query, @Nullable Class<?> entityClass, String collectionName) { if (!session.hasActiveTransaction()) { return super.count(query, entityClass, collectionName); } return createMono(collectionName, collection -> { Document filter = query == null ? null : delegate.queryMapper.getMappedObject(query.getQueryObject(), entityClass == null ? null : delegate.mappingContext.getPersistentEntity(entityClass)); CountOptions options = new CountOptions(); if (query != null) { query.getCollation().map(Collation::toMongoCollation).ifPresent(options::collation); } if (LOGGER.isDebugEnabled()) { LOGGER.debug("Executing count: {} in collection: {}", serializeToJsonSafely(filter), collectionName); } return collection.countDocuments(filter, options); }); } }
@Override public Boolean doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException { return doCount(collection.getNamespace().getCollectionName(), mappedQuery, new CountOptions().limit(1).collation(collation)) > 0; } }
@Override @SuppressWarnings("deprecation") public long count(final ClientSession clientSession, final Bson filter) { return count(clientSession, filter, new CountOptions()); }
@Override @SuppressWarnings("deprecation") public long count() { return count(new BsonDocument(), new CountOptions()); }
@Override @SuppressWarnings("deprecation") public long count() { return count(new BsonDocument(), new CountOptions()); }
@Test public void testQuerySkipLimitSimpleQuery() throws Exception { assertThat(collection.countDocuments(json("a: 1"), new CountOptions().skip(3))).isEqualTo(0); for (int i = 0; i < 10; i++) { collection.insertOne(json("a: 1")); } assertThat(collection.countDocuments(json("a: 1"), new CountOptions().skip(3))).isEqualTo(7); assertThat(collection.countDocuments(json("a: 1"), new CountOptions().skip(3).limit(5))).isEqualTo(5); assertThat(collection.countDocuments(json("a: 1"), new CountOptions().skip(15).limit(5))).isEqualTo(0); }
@Override public boolean isQueueEmpty() { return (int) collRefs.count(eq(IMongoSerializer.FIELD_STAGE, Stage.QUEUED.name()), new CountOptions().limit(1)) == 0; }