driver-legacy/src/main/com/mongodb/DBCollection.java
public long getCount(@Nullable final DBObject query, final DBCollectionCountOptions options) {
        notNull("countOptions", options);
        CountOperation operation = new CountOperation(getNamespace())
                                       .skip(options.getSkip())
                                       .limit(options.getLimit())
                                       .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS)
                                       .collation(options.getCollation())
                                       .retryReads(retryReads);
        if (query != null) {
            operation.filter(wrap(query));
        }
        DBObject hint = options.getHint();
        if (hint != null) {
            operation.hint(wrap(hint));
        } else {
            String hintString = options.getHintString();
            if (hintString != null) {
                operation.hint(new BsonString(hintString));
            }
        }
        ReadPreference optionsReadPreference = options.getReadPreference();
        ReadConcern optionsReadConcern = options.getReadConcern();
        return executor.execute(operation, optionsReadPreference != null ? optionsReadPreference : getReadPreference(),
                optionsReadConcern != null ? optionsReadConcern : getReadConcern());
    }
public long getCount(@Nullable final DBObject query, final DBCollectionCountOptions options) {
        notNull("countOptions", options);
        CountOperation operation = new CountOperation(getNamespace())
                                       .skip(options.getSkip())
                                       .limit(options.getLimit())
                                       .maxTime(options.getMaxTime(MILLISECONDS), MILLISECONDS)
                                       .collation(options.getCollation())
                                       .retryReads(retryReads);
        if (query != null) {
            operation.filter(wrap(query));
        }
        DBObject hint = options.getHint();
        if (hint != null) {
            operation.hint(wrap(hint));
        } else {
            String hintString = options.getHintString();
            if (hintString != null) {
                operation.hint(new BsonString(hintString));
            }
        }
        ReadPreference optionsReadPreference = options.getReadPreference();
        ReadConcern optionsReadConcern = options.getReadConcern();
        return executor.execute(operation, optionsReadPreference != null ? optionsReadPreference : getReadPreference(),
                optionsReadConcern != null ? optionsReadConcern : getReadConcern());
    }
public long getCount ( @ Nullable final DBObject query , final DBCollectionCountOptions options ) { notNull ( "countOptions" , options ) ; CountOperation operation = new CountOperation ( getNamespace ( ) ) . skip ( options . getSkip ( ) ) . limit ( options . getLimit ( ) ) . maxTime ( options . getMaxTime ( MILLISECONDS ) , MILLISECONDS ) . collation ( options . getCollation ( ) ) . retryReads ( retryReads ) ; if ( query != null ) { operation . filter ( wrap ( query ) ) ; } DBObject hint = options . getHint ( ) ; if ( hint != null ) { operation . hint ( wrap ( hint ) ) ; } else { String hintString = options . getHintString ( ) ; if ( hintString != null ) { operation . hint ( new BsonString ( hintString ) ) ; } } ReadPreference optionsReadPreference = options . getReadPreference ( ) ; ReadConcern optionsReadConcern = options . getReadConcern ( ) ; return executor . execute ( operation , optionsReadPreference != null ? optionsReadPreference : getReadPreference ( ) , optionsReadConcern != null ? optionsReadConcern : getReadConcern ( ) ) ; }
Get the count of documents in collection that would match a criteria.

@param query     specifies the selection criteria
@param options   the options for the count operation.
@return the number of documents that matches selection criteria
@throws MongoException if the operation failed
@mongodb.driver.manual reference/command/count/ Count
@since 3.4
Get the count of documents in collection that would match a criteria .