下面列出了怎么用com.mongodb.client.model.IndexModel的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* 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);
}
@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);
}
@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);
}
}));
}
@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);
}
}));
}
@Override
public Uni<List<String>> createIndexes(List<IndexModel> indexes) {
return Wrappers.toUniOfList(collection.createIndexes(indexes));
}
@Override
public Uni<List<String>> createIndexes(List<IndexModel> indexes, CreateIndexOptions createIndexOptions) {
return Wrappers.toUniOfList(collection.createIndexes(indexes, createIndexOptions));
}
@Override
public Uni<List<String>> createIndexes(ClientSession clientSession, List<IndexModel> indexes) {
return Wrappers.toUniOfList(collection.createIndexes(clientSession, indexes));
}
@Override
public Uni<List<String>> createIndexes(ClientSession clientSession, List<IndexModel> indexes,
CreateIndexOptions createIndexOptions) {
return Wrappers.toUniOfList(collection.createIndexes(clientSession, indexes, createIndexOptions));
}
public MongoIndex add(MongoIndex mongoIndex) {
indexModels.add(new IndexModel(Indexes.compoundIndex(mongoIndex.getBson()), mongoIndex));
return this;
}
@Override
public Publisher<String> createIndexes(final List<IndexModel> indexes) {
return createIndexes(indexes, new CreateIndexOptions());
}
@Override
public Publisher<String> createIndexes(final ClientSession clientSession, final List<IndexModel> indexes) {
return createIndexes(clientSession, indexes, new CreateIndexOptions());
}
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
}
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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);