com.mongodb.client.model.IndexModel Java Examples

The following examples show how to use com.mongodb.client.model.IndexModel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Index.java    From ditto with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Creates a new {@link IndexModel}, which can be used for creating indices using MongoDB Java drivers.
 *
 * @return the created {@link IndexModel}
 */
public IndexModel toIndexModel() {
    final IndexOptions options = new IndexOptions()
            .name(name)
            .unique(unique)
            .sparse(sparse)
            .background(background);

    if (!partialFilterExpression.isEmpty()) {
        options.partialFilterExpression(partialFilterExpression);
    }

    getExpireAfterSeconds().ifPresent(n -> options.expireAfter(n, TimeUnit.SECONDS));

    return new IndexModel(keys, options);
}
 
Example #2
Source File: MongoCollectionImpl.java    From mongo-java-driver-rx with Apache License 2.0 5 votes vote down vote up
@Override
public Observable<String> createIndexes(final List<IndexModel> indexes) {
    return RxObservables.create(Observables.observeAndFlatten(new Block<SingleResultCallback<List<String>>>() {
        @Override
        public void apply(final SingleResultCallback<List<String>> callback) {
            wrapped.createIndexes(indexes, callback);
        }
    }), observableAdapter);
}
 
Example #3
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 5 votes vote down vote up
@Override
public Publisher<String> createIndexes(final ClientSession clientSession, final List<IndexModel> indexes,
                                       final CreateIndexOptions createIndexOptions) {
    return new ObservableToPublisher<String>(com.mongodb.async.client.Observables.observeAndFlatten(
            new Block<com.mongodb.async.SingleResultCallback<List<String>>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<List<String>> callback) {
                    wrapped.createIndexes(clientSession.getWrapped(), indexes, createIndexOptions, callback);
                }
            }));
}
 
Example #4
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 5 votes vote down vote up
@Override
public Publisher<String> createIndexes(final List<IndexModel> indexes, final CreateIndexOptions createIndexOptions) {
    return new ObservableToPublisher<String>(com.mongodb.async.client.Observables.observeAndFlatten(
            new Block<com.mongodb.async.SingleResultCallback<List<String>>>() {
                @Override
                public void apply(final com.mongodb.async.SingleResultCallback<List<String>> callback) {
                    wrapped.createIndexes(indexes, createIndexOptions, callback);
                }
            }));
}
 
Example #5
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<List<String>> createIndexes(List<IndexModel> indexes) {
    return Wrappers.toUniOfList(collection.createIndexes(indexes));
}
 
Example #6
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<List<String>> createIndexes(List<IndexModel> indexes, CreateIndexOptions createIndexOptions) {
    return Wrappers.toUniOfList(collection.createIndexes(indexes, createIndexOptions));
}
 
Example #7
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<List<String>> createIndexes(ClientSession clientSession, List<IndexModel> indexes) {
    return Wrappers.toUniOfList(collection.createIndexes(clientSession, indexes));
}
 
Example #8
Source File: ReactiveMongoCollectionImpl.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
public Uni<List<String>> createIndexes(ClientSession clientSession, List<IndexModel> indexes,
        CreateIndexOptions createIndexOptions) {
    return Wrappers.toUniOfList(collection.createIndexes(clientSession, indexes, createIndexOptions));
}
 
Example #9
Source File: MongoIndex.java    From MongoDB-Plugin with Apache License 2.0 4 votes vote down vote up
public MongoIndex add(MongoIndex mongoIndex) {
    indexModels.add(new IndexModel(Indexes.compoundIndex(mongoIndex.getBson()), mongoIndex));
    return this;
}
 
Example #10
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<String> createIndexes(final List<IndexModel> indexes) {
    return createIndexes(indexes, new CreateIndexOptions());
}
 
Example #11
Source File: MongoCollectionImpl.java    From mongo-java-driver-reactivestreams with Apache License 2.0 4 votes vote down vote up
@Override
public Publisher<String> createIndexes(final ClientSession clientSession, final List<IndexModel> indexes) {
    return createIndexes(clientSession, indexes, new CreateIndexOptions());
}
 
Example #12
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Create multiple indexes.
 *
 * @param clientSession the client session with which to associate this operation
 * @param indexes the list of indexes
 * @param createIndexOptions options to use when creating indexes
 * @return a publisher with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/command/createIndexes Create indexes
 * @mongodb.server.release 3.6
 * @since 1.7
 */
Publisher<String> createIndexes(ClientSession clientSession, List<IndexModel> indexes, CreateIndexOptions createIndexOptions);
 
Example #13
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Create multiple indexes.
 *
 * @param indexes the list of indexes
 * @return a {@link Uni} completed with the result when the operation is done. The redeemed list contains the
 *         created index names.
 */
Uni<List<String>> createIndexes(List<IndexModel> indexes);
 
Example #14
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Create multiple indexes.
 *
 * @param clientSession the client session with which to associate this operation
 * @param indexes the list of indexes
 * @return a publisher with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/command/createIndexes Create indexes
 * @mongodb.server.release 3.6
 * @since 1.7
 */
Publisher<String> createIndexes(ClientSession clientSession, List<IndexModel> indexes);
 
Example #15
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Create multiple indexes.
 *
 * @param indexes the list of indexes
 * @param createIndexOptions options to use when creating indexes
 * @return a publisher with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/command/createIndexes Create indexes
 * @mongodb.server.release 2.6
 * @since 1.7
 */
Publisher<String> createIndexes(List<IndexModel> indexes, CreateIndexOptions createIndexOptions);
 
Example #16
Source File: MongoCollection.java    From mongo-java-driver-reactivestreams with Apache License 2.0 2 votes vote down vote up
/**
 * Create multiple indexes.
 *
 * @param indexes the list of indexes
 * @return a publisher with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/command/createIndexes Create indexes
 * @mongodb.server.release 2.6
 */
Publisher<String> createIndexes(List<IndexModel> indexes);
 
Example #17
Source File: MongoCollection.java    From mongo-java-driver-rx with Apache License 2.0 2 votes vote down vote up
/**
 * Create multiple indexes.
 *
 * @param indexes the list of indexes
 * @return an Observable with a single element indicating when the operation has completed
 * @mongodb.driver.manual reference/command/createIndexes Create indexes
 * @mongodb.server.release 2.6
 */
Observable<String> createIndexes(List<IndexModel> indexes);
 
Example #18
Source File: IndexOperations.java    From ditto with Eclipse Public License 2.0 2 votes vote down vote up
/**
 * Creates the specified index. Throws an exception if the index with the same name already exists.
 *
 * <p>
 * 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);
}
 
Example #19
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Create multiple indexes.
 *
 * @param clientSession the client session with which to associate this operation
 * @param indexes the list of indexes
 * @param createIndexOptions options to use when creating indexes
 * @return a {@link Uni} completed with the result when the operation is done. The redeemed list contains the
 *         created index names.
 */
Uni<List<String>> createIndexes(ClientSession clientSession, List<IndexModel> indexes,
        CreateIndexOptions createIndexOptions);
 
Example #20
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Create multiple indexes.
 *
 * @param clientSession the client session with which to associate this operation
 * @param indexes the list of indexes
 * @return a {@link Uni} completed with the result when the operation is done. The redeemed list contains the
 *         created index names.
 */
Uni<List<String>> createIndexes(ClientSession clientSession, List<IndexModel> indexes);
 
Example #21
Source File: ReactiveMongoCollection.java    From quarkus with Apache License 2.0 2 votes vote down vote up
/**
 * Create multiple indexes.
 *
 * @param indexes the list of indexes
 * @param createIndexOptions options to use when creating indexes
 * @return a {@link Uni} completed with the result when the operation is done. The redeemed list contains the
 *         created index names.
 */
Uni<List<String>> createIndexes(List<IndexModel> indexes, CreateIndexOptions createIndexOptions);