Skip to content

Commit 0488466

Browse files
committed
Reduce code duplication
1 parent 28c937f commit 0488466

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

core/src/main/java/de/bwaldvogel/mongo/backend/AbstractMongoDatabase.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -427,22 +427,21 @@ private void dropIndexes(MongoCollection<P> collection, Document query) {
427427
Object index = query.get("index");
428428
Assert.notNull(index, () -> "Index name must not be null");
429429
MongoCollection<P> indexCollection = indexes.get();
430+
Document nsQuery = new Document("ns", collection.getFullName());
430431
if (Objects.equals(index, "*")) {
431-
Document nsQuery = new Document("ns", collection.getFullName());
432432
for (Document indexDocument : indexCollection.handleQuery(nsQuery)) {
433433
Document indexKeys = (Document) indexDocument.get("key");
434434
if (!isPrimaryKeyIndex(indexKeys)) {
435435
dropIndex(collection, indexDocument);
436436
}
437437
}
438438
} else {
439-
Document indexQuery = new Document("ns", collection.getFullName());
440439
if (index instanceof String indexName) {
441-
indexQuery.append("name", indexName);
440+
nsQuery.append("name", indexName);
442441
} else {
443-
indexQuery.append("key", (Document) index);
442+
nsQuery.append("key", (Document) index);
444443
}
445-
Document indexToDrop = CollectionUtils.getSingleElement(indexCollection.handleQuery(indexQuery),
444+
Document indexToDrop = CollectionUtils.getSingleElement(indexCollection.handleQuery(nsQuery),
446445
() -> createIndexNotFoundException(index));
447446
int numDeleted = dropIndex(collection, indexToDrop);
448447
Assert.equals(numDeleted, 1, () -> "Expected one deleted document");

0 commit comments

Comments
 (0)