use of com.mongodb.client.model.EstimatedDocumentCountOptions in project mongo-java-driver by mongodb.
the class UnifiedCrudHelper method executeEstimatedDocumentCount.
public OperationResult executeEstimatedDocumentCount(final BsonDocument operation) {
MongoCollection<BsonDocument> collection = entities.getCollection(operation.getString("object").getValue());
BsonDocument arguments = operation.getDocument("arguments", new BsonDocument());
EstimatedDocumentCountOptions options = new EstimatedDocumentCountOptions();
for (Map.Entry<String, BsonValue> cur : arguments.entrySet()) {
// noinspection SwitchStatementWithTooFewBranches
switch(cur.getKey()) {
case "maxTimeMS":
options.maxTime(cur.getValue().asNumber().intValue(), TimeUnit.MILLISECONDS);
break;
default:
throw new UnsupportedOperationException("Unsupported argument: " + cur.getKey());
}
}
return resultOf(() -> new BsonInt64(collection.estimatedDocumentCount(options)));
}
use of com.mongodb.client.model.EstimatedDocumentCountOptions in project mongo-java-driver by mongodb.
the class MongoCollectionImplTest method testEstimatedDocumentCount.
@Test
public void testEstimatedDocumentCount() {
EstimatedDocumentCountOptions options = new EstimatedDocumentCountOptions().maxTime(1, TimeUnit.MILLISECONDS);
assertAll("estimatedDocumentCount", () -> assertAll("check validation", () -> assertThrows(IllegalArgumentException.class, () -> collection.estimatedDocumentCount(null))), () -> {
Publisher<Long> expected = mongoOperationPublisher.estimatedDocumentCount(new EstimatedDocumentCountOptions());
assertPublisherIsTheSameAs(expected, collection.estimatedDocumentCount(), "Default");
}, () -> {
Publisher<Long> expected = mongoOperationPublisher.estimatedDocumentCount(options);
assertPublisherIsTheSameAs(expected, collection.estimatedDocumentCount(options), "With options");
});
}
Aggregations