Example usage for com.mongodb.client.model IndexModel getKeys

List of usage examples for com.mongodb.client.model IndexModel getKeys

Introduction

In this page you can find the example usage for com.mongodb.client.model IndexModel getKeys.

Prototype

public Bson getKeys() 

Source Link

Document

Gets the index keys.

Usage

From source file:org.eclipse.ditto.services.utils.persistence.mongo.indices.IndexOperations.java

License:Open Source License

/**
 * Creates the specified index. Throws an exception if the index with the same name already exists.
 *
 * <p>/* w w  w  . java 2  s  . c o m*/
 * Just does nothing if another index for the same keys with conflicting options already exists. For details, see
 * the <a href="https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/">MongoDB documentation</a>.
 * </p>
 *
 * @param collectionName the name of the collection containing the index.
 * @param index the index.
 * @return a source which emits {@link Success}.
 */
public Source<Success, NotUsed> createIndex(final String collectionName, final Index index) {
    final IndexModel indexModel = index.toIndexModel();
    return Source
            .fromPublisher(
                    getCollection(collectionName).createIndex(indexModel.getKeys(), indexModel.getOptions()))
            .map(unused -> Success.SUCCESS);
}