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

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

Introduction

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

Prototype

public IndexOptions getOptions() 

Source Link

Document

Gets the index options.

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 .j  ava2 s. co 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);
}