|
35 | 35 | import static com.mongodb.assertions.Assertions.isTrueArgument;
|
36 | 36 | import static com.mongodb.assertions.Assertions.notNull;
|
37 | 37 | import static com.mongodb.internal.async.ErrorHandlingResultCallback.errorHandlingCallback;
|
| 38 | +import static com.mongodb.internal.operation.WriteConcernHelper.appendWriteConcernToCommand; |
38 | 39 | import static com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocol;
|
39 | 40 | import static com.mongodb.operation.CommandOperationHelper.executeWrappedCommandProtocolAsync;
|
40 | 41 | import static com.mongodb.operation.CommandOperationHelper.isNamespaceError;
|
| 42 | +import static com.mongodb.operation.CommandOperationHelper.writeConcernErrorTransformer; |
41 | 43 | import static com.mongodb.operation.DocumentHelper.putIfNotZero;
|
42 |
| -import static com.mongodb.internal.operation.IndexHelper.generateIndexName; |
43 | 44 | import static com.mongodb.operation.OperationHelper.LOGGER;
|
44 | 45 | import static com.mongodb.operation.OperationHelper.releasingCallback;
|
45 | 46 | import static com.mongodb.operation.OperationHelper.withConnection;
|
46 |
| -import static com.mongodb.internal.operation.WriteConcernHelper.appendWriteConcernToCommand; |
47 |
| -import static com.mongodb.operation.CommandOperationHelper.writeConcernErrorTransformer; |
48 | 47 |
|
49 | 48 | /**
|
50 | 49 | * An operation that drops an index.
|
|
55 | 54 | public class DropIndexOperation implements AsyncWriteOperation<Void>, WriteOperation<Void> {
|
56 | 55 | private final MongoNamespace namespace;
|
57 | 56 | private final String indexName;
|
| 57 | + private final BsonDocument indexKeys; |
58 | 58 | private final WriteConcern writeConcern;
|
59 | 59 | private long maxTimeMS;
|
60 | 60 |
|
@@ -93,20 +93,22 @@ public DropIndexOperation(final MongoNamespace namespace, final BsonDocument key
|
93 | 93 | public DropIndexOperation(final MongoNamespace namespace, final String indexName, final WriteConcern writeConcern) {
|
94 | 94 | this.namespace = notNull("namespace", namespace);
|
95 | 95 | this.indexName = notNull("indexName", indexName);
|
| 96 | + this.indexKeys = null; |
96 | 97 | this.writeConcern = writeConcern;
|
97 | 98 | }
|
98 | 99 |
|
99 | 100 | /**
|
100 | 101 | * Construct a new instance.
|
101 | 102 | *
|
102 | 103 | * @param namespace the database and collection namespace for the operation.
|
103 |
| - * @param keys the keys of the index to be dropped |
| 104 | + * @param indexKeys the keys of the index to be dropped |
104 | 105 | * @param writeConcern the write concern
|
105 | 106 | * @since 3.4
|
106 | 107 | */
|
107 |
| - public DropIndexOperation(final MongoNamespace namespace, final BsonDocument keys, final WriteConcern writeConcern) { |
| 108 | + public DropIndexOperation(final MongoNamespace namespace, final BsonDocument indexKeys, final WriteConcern writeConcern) { |
108 | 109 | this.namespace = notNull("namespace", namespace);
|
109 |
| - this.indexName = generateIndexName(notNull("keys", keys)); |
| 110 | + this.indexKeys = notNull("indexKeys", indexKeys); |
| 111 | + this.indexName = null; |
110 | 112 | this.writeConcern = writeConcern;
|
111 | 113 | }
|
112 | 114 |
|
@@ -190,8 +192,13 @@ public void onResult(final Void result, final Throwable t) {
|
190 | 192 | }
|
191 | 193 |
|
192 | 194 | private BsonDocument getCommand(final ConnectionDescription description) {
|
193 |
| - BsonDocument command = new BsonDocument("dropIndexes", new BsonString(namespace.getCollectionName())) |
194 |
| - .append("index", new BsonString(indexName)); |
| 195 | + BsonDocument command = new BsonDocument("dropIndexes", new BsonString(namespace.getCollectionName())); |
| 196 | + if (indexName != null) { |
| 197 | + command.put("index", new BsonString(indexName)); |
| 198 | + } else { |
| 199 | + command.put("index", indexKeys); |
| 200 | + } |
| 201 | + |
195 | 202 | putIfNotZero(command, "maxTimeMS", maxTimeMS);
|
196 | 203 | appendWriteConcernToCommand(writeConcern, command, description);
|
197 | 204 | return command;
|
|
0 commit comments