Example usage for com.mongodb.async.client MongoCollection distinct

List of usage examples for com.mongodb.async.client MongoCollection distinct

Introduction

In this page you can find the example usage for com.mongodb.async.client MongoCollection distinct.

Prototype

<TResult> DistinctIterable<TResult> distinct(String fieldName, Class<TResult> resultClass);

Source Link

Document

Gets the distinct values of the specified field name.

Usage

From source file:io.vertx.ext.mongo.impl.MongoClientImpl.java

License:Open Source License

private DistinctIterable findDistinctValues(String collection, String fieldName, String resultClassname,
        Handler resultHandler) {//from  w  w w .  j ava  2 s. co  m
    requireNonNull(collection, "collection cannot be null");
    requireNonNull(fieldName, "fieldName cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    final Class resultClass;
    try {
        resultClass = Class.forName(resultClassname);
    } catch (ClassNotFoundException e) {
        resultHandler.handle(Future.failedFuture(e));
        return null;
    }
    MongoCollection<JsonObject> mongoCollection = getCollection(collection);
    return mongoCollection.distinct(fieldName, resultClass);
}