Skip to content

Commit

Permalink
fixes #156 propagate create index exception in ensureIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
zigzago committed Nov 21, 2019
1 parent 7710265 commit 98ee409
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,11 @@ fun <T> MongoCollection<T>.ensureIndex(keys: String, indexOptions: IndexOptions
} catch (e: MongoCommandException) {
//there is an exception if the parameters of an existing index are changed.
//then drop the index and create a new one
dropIndexOfKeys(keys)
try {
dropIndexOfKeys(keys)
} catch (e2: Exception) {
//ignore
}
createIndex(keys, indexOptions)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,11 @@ fun <T> MongoCollection<T>.ensureIndex(
} catch (e: MongoCommandException) {
//there is an exception if the parameters of an existing index are changed.
//then drop the index and create a new one
dropIndex(clientSession, keys)
try {
dropIndex(clientSession, keys)
} catch (e2: Exception) {
//ignore
}
createIndex(clientSession, keys, indexOptions)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,13 @@ suspend fun <T> MongoCollection<T>.ensureIndex(
} catch (e: MongoCommandException) {
//there is an exception if the parameters of an existing index are changed.
//then drop the index and create a new one
singleResult<Void> { dropIndex(keys, it) }
singleResult<Void> {
try {
dropIndex(keys, it)
} catch (e2: Exception) {
//ignore
}
}
singleResult { createIndex(keys, indexOptions, it) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,7 @@ fun <T> MongoCollection<T>.ensureIndex(keys: String, indexOptions: IndexOptions
return createIndex(keys, indexOptions)
.onErrorResumeNext(
dropIndex(keys)
.onErrorComplete()
.andThen(createIndex(keys, indexOptions))
)
.flatMapCompletable { _ ->
Expand All @@ -763,6 +764,7 @@ fun <T> MongoCollection<T>.ensureIndex(
return maybeResult<String> { createIndex(keys, indexOptions, it) }
.onErrorResumeNext(
completableResult { dropIndex(keys, it) }
.onErrorComplete()
.andThen(maybeResult { createIndex(keys, indexOptions, it) })
)
.flatMapCompletable { _ ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,7 @@ fun <T> MongoCollection<T>.ensureIndex(keys: String, indexOptions: IndexOptions
.onErrorResumeNext(
dropIndex(keys)
.completable()
.onErrorComplete()
.andThen(createIndex(keys, indexOptions))
)
.flatMapCompletable { _ ->
Expand All @@ -569,7 +570,9 @@ fun <T> MongoCollection<T>.ensureIndex(
): Completable {
return createIndex(keys, indexOptions).maybe()
.onErrorResumeNext(
dropIndex(keys).completable()
dropIndex(keys)
.completable()
.onErrorComplete()
.andThen(createIndex(keys, indexOptions).maybe())
)
.flatMapCompletable { _ ->
Expand Down

0 comments on commit 98ee409

Please sign in to comment.