List of usage examples for com.mongodb.async.client MongoCollection dropIndex
void dropIndex(Bson keys, SingleResultCallback<Void> callback);
From source file:io.vertx.ext.mongo.impl.MongoClientImpl.java
License:Open Source License
@Override public MongoClient dropIndex(String collection, String indexName, Handler<AsyncResult<Void>> resultHandler) { requireNonNull(collection, "collection cannot be null"); requireNonNull(indexName, "indexName cannot be null"); requireNonNull(resultHandler, "resultHandler cannot be null"); MongoCollection<JsonObject> coll = getCollection(collection); coll.dropIndex(indexName, wrapCallback(resultHandler)); return this; }
From source file:org.openo.commontosca.inventory.core.mongo.handler.model.MongoModelUpdateRequestHandler.java
License:Apache License
private void ensureDataCollectionIndex(MongoCollection<Document> dataCollection, List<ValueMap> allIndexes, String attributeName, boolean hasIndex, boolean uniqueIndex) throws Exception { Optional<ValueMap> findIndex = allIndexes.stream().filter(map -> { return map.requireMap("key").get(attributeName) != null; }).findAny();/*w w w . j a v a2 s .c o m*/ if (findIndex.isPresent()) { ValueMap theIndex = findIndex.get(); String indexName = theIndex.requireString("name"); if (hasIndex) { boolean oldIsUnique = theIndex.optBoolean("unique", false); if (uniqueIndex != oldIsUnique) { DeferredSingleResult.<Void>execute(deferred -> { dataCollection.dropIndex(indexName, deferred); }); allIndexes.removeIf(map -> { return map.requireMap("key").get(attributeName) != null; }); this.ensureDataCollectionIndex(dataCollection, allIndexes, attributeName, hasIndex, uniqueIndex); } } else { DeferredSingleResult.<Void>execute(deferred -> { dataCollection.dropIndex(indexName, deferred); }); } } else if (hasIndex) { DeferredSingleResult.<String>execute(deferred -> { dataCollection.createIndex(Indexes.ascending(attributeName), new IndexOptions().unique(uniqueIndex), deferred); }); } }