Example usage for com.mongodb.client.model CountOptions maxTime

List of usage examples for com.mongodb.client.model CountOptions maxTime

Introduction

In this page you can find the example usage for com.mongodb.client.model CountOptions maxTime.

Prototype

public CountOptions maxTime(final long maxTime, final TimeUnit timeUnit) 

Source Link

Document

Sets the maximum execution time on the server for this operation.

Usage

From source file:io.djigger.collector.accessors.stackref.ThreadInfoAccessorImpl.java

License:Open Source License

public long count(Bson mongoQuery, Date from, Date to, long timeout, TimeUnit timeUnit)
        throws TimeoutException {
    mongoQuery = buildQuery(mongoQuery, from, to);

    CountOptions options = new CountOptions();
    options.maxTime(timeout, timeUnit);

    try {//from ww  w. ja va 2s. com
        return threadInfoCollection.count(mongoQuery, options);
    } catch (MongoExecutionTimeoutException e) {
        throw new TimeoutException("Count exceeded time limit");
    }
}