ensureIndex

fun <T : Any> MongoCollection<T>.ensureIndex(keys: Bson, indexOptions: IndexOptions = IndexOptions()): String
fun <T : Any> MongoCollection<T>.ensureIndex(keys: String, indexOptions: IndexOptions = IndexOptions()): String

Create an index with the given keys and options. If the creation of the index is not doable because an index with the same keys but with different IndexOptions already exists, then drop the existing index and create a new one.

Return

the index name

Parameters

keys

an object describing the index key(s), which may not be null.

indexOptions

the options for the index


fun <T : Any> MongoCollection<T>.ensureIndex(vararg properties: KProperty<*>, indexOptions: IndexOptions = IndexOptions()): String

Create an ascending index with the given keys and options. If the creation of the index is not doable because an index with the same keys but with different IndexOptions already exists, then drop the existing index and create a new one.

Return

the index name

Parameters

keys

the properties, which must contain at least one

indexOptions

the options for the index


fun <T : Any> MongoCollection<T>.ensureIndex(clientSession: ClientSession, keys: Bson, indexOptions: IndexOptions = IndexOptions()): String
fun <T : Any> MongoCollection<T>.ensureIndex(clientSession: ClientSession, keys: String, indexOptions: IndexOptions = IndexOptions()): String

Create an index with the given keys and options. If the creation of the index is not doable because an index with the same keys but with different IndexOptions already exists, then drop the existing index and create a new one.

Return

the index name

Parameters

clientSession

the client session with which to associate this operation

keys

an object describing the index key(s), which may not be null.

indexOptions

the options for the index


fun <T : Any> MongoCollection<T>.ensureIndex(clientSession: ClientSession, vararg properties: KProperty<*>, indexOptions: IndexOptions = IndexOptions()): String

Create an ascending index with the given keys and options. If the creation of the index is not doable because an index with the same keys but with different IndexOptions already exists, then drop the existing index and create a new one.

Return

the index name

Parameters

clientSession

the client session with which to associate this operation

keys

the properties, which must contain at least one

indexOptions

the options for the index