Package-level declarations

Types

Link copied to clipboard
object KMongo

Main object used to create a MongoClient instance of the official MongoDB Kotlin sync driver, configured with the KMongo object mapping.

Functions

Link copied to clipboard
inline fun <TResult : Any> MongoCollection<*>.aggregate(vararg pipeline: String): AggregateIterable<TResult>
inline fun <TResult : Any> MongoCollection<*>.aggregate(vararg pipeline: Bson): AggregateIterable<TResult>
inline fun <TResult : Any> MongoCollection<*>.aggregate(clientSession: ClientSession, vararg pipeline: String): AggregateIterable<TResult>
inline fun <TResult : Any> MongoCollection<*>.aggregate(clientSession: ClientSession, vararg pipeline: Bson): AggregateIterable<TResult>

Aggregates documents according to the specified aggregation pipeline.

Link copied to clipboard
inline fun <T> MongoIterable<T>.all(crossinline predicate: (T) -> Boolean): Boolean

Returns true if all elements match the given predicate.

Link copied to clipboard
fun <T> MongoIterable<T>.any(): Boolean

Returns true if collection has at least one element.

inline fun <T> MongoIterable<T>.any(crossinline predicate: (T) -> Boolean): Boolean

Returns true if at least one element matches the given predicate.

Link copied to clipboard
fun <T : Any> FindIterable<T>.ascendingSort(vararg properties: KProperty<*>): FindIterable<T>

Sets the sort criteria with specified ascending properties to apply to the query.

Link copied to clipboard
fun <T> MongoIterable<T>.asSequence(): Sequence<T>

Returns a (non lazy) Sequence of the elements.

Link copied to clipboard
inline fun <T, K, V> MongoIterable<T>.associate(crossinline transform: (T) -> Pair<K, V>): Map<K, V>

Returns a Map containing key-value pairs provided by transform function applied to elements of the given collection.

Link copied to clipboard
inline fun <T, K> MongoIterable<T>.associateBy(crossinline keySelector: (T) -> K): Map<K, T>

Returns a Map containing the elements from the given collection indexed by the key returned from keySelector function applied to each element.

inline fun <T, K, V> MongoIterable<T>.associateBy(crossinline keySelector: (T) -> K, crossinline valueTransform: (T) -> V): Map<K, V>

Returns a Map containing the values provided by valueTransform and indexed by keySelector functions applied to elements of the given collection.

Link copied to clipboard
inline fun <T, K, M : MutableMap<in K, in T>> MongoIterable<T>.associateByTo(destination: M, crossinline keySelector: (T) -> K): M

Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function applied to each element of the given collection and value is the element itself.

inline fun <T, K, V, M : MutableMap<in K, in V>> MongoIterable<T>.associateByTo(destination: M, crossinline keySelector: (T) -> K, crossinline valueTransform: (T) -> V): M

Populates and returns the destination mutable map with key-value pairs, where key is provided by the keySelector function and and value is provided by the valueTransform function applied to elements of the given collection.

Link copied to clipboard
inline fun <T, K, V, M : MutableMap<in K, in V>> MongoIterable<T>.associateTo(destination: M, crossinline transform: (T) -> Pair<K, V>): M

Populates and returns the destination mutable map with key-value pairs provided by transform function applied to each element of the given collection.

Link copied to clipboard
@JvmName(name = "averageOfByte")
fun MongoIterable<Byte>.average(): Double
@JvmName(name = "averageOfDouble")
fun MongoIterable<Double>.average(): Double
@JvmName(name = "averageOfFloat")
fun MongoIterable<Float>.average(): Double
@JvmName(name = "averageOfInt")
fun MongoIterable<Int>.average(): Double
@JvmName(name = "averageOfLong")
fun MongoIterable<Long>.average(): Double
@JvmName(name = "averageOfShort")
fun MongoIterable<Short>.average(): Double

Returns an average value of elements in the collection.

Link copied to clipboard
inline fun <T : Any> MongoCollection<T>.bulkWrite(vararg requests: WriteModel<T>, options: BulkWriteOptions = BulkWriteOptions()): BulkWriteResult
inline fun <T : Any> MongoCollection<T>.bulkWrite(vararg requests: String, options: BulkWriteOptions = BulkWriteOptions()): BulkWriteResult
inline fun <T : Any> MongoCollection<T>.bulkWrite(clientSession: ClientSession, vararg requests: WriteModel<T>, options: BulkWriteOptions = BulkWriteOptions()): BulkWriteResult
inline fun <T : Any> MongoCollection<T>.bulkWrite(clientSession: ClientSession, vararg requests: String, options: BulkWriteOptions = BulkWriteOptions()): BulkWriteResult

Executes a mix of inserts, updates, replaces, and deletes.

Link copied to clipboard
fun <T> MongoIterable<T>.chunked(size: Int): List<List<T>>

Splits this collection into a list of lists each not exceeding the given size.

fun <T, R> MongoIterable<T>.chunked(size: Int, transform: (List<T>) -> R): List<R>

Splits this collection into several lists each not exceeding the given size and applies the given transform function to an each.

Link copied to clipboard
operator fun <T> MongoIterable<T>.contains(element: T): Boolean

Returns true if element is found in the collection.

Link copied to clipboard
fun <T> MongoIterable<T>.count(): Int

Returns the number of elements in this collection.

inline fun <T> MongoIterable<T>.count(crossinline predicate: (T) -> Boolean): Int

Returns the number of elements matching the given predicate.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.countDocuments(filter: String, options: CountOptions = CountOptions()): Long
fun <T : Any> MongoCollection<T>.countDocuments(clientSession: ClientSession, filter: String, options: CountOptions = CountOptions()): Long

Counts the number of documents in the collection according to the given options.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.createIndex(keys: String, indexOptions: IndexOptions = IndexOptions()): String
fun <T : Any> MongoCollection<T>.createIndex(clientSession: ClientSession, keys: String, indexOptions: IndexOptions = IndexOptions()): String

Create an index with the given keys and options.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.deleteMany(filter: String, options: DeleteOptions = DeleteOptions()): DeleteResult
fun <T : Any> MongoCollection<T>.deleteMany(vararg filters: Bson?, options: DeleteOptions = DeleteOptions()): DeleteResult
fun <T : Any> MongoCollection<T>.deleteMany(clientSession: ClientSession, filter: String, options: DeleteOptions = DeleteOptions()): DeleteResult
fun <T : Any> MongoCollection<T>.deleteMany(clientSession: ClientSession, vararg filters: Bson?, options: DeleteOptions = DeleteOptions()): DeleteResult

Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.deleteOne(filter: String, deleteOptions: DeleteOptions = DeleteOptions()): DeleteResult
fun <T : Any> MongoCollection<T>.deleteOne(vararg filters: Bson?, deleteOptions: DeleteOptions = DeleteOptions()): DeleteResult
fun <T : Any> MongoCollection<T>.deleteOne(clientSession: ClientSession, filter: String, deleteOptions: DeleteOptions = DeleteOptions()): DeleteResult
fun <T : Any> MongoCollection<T>.deleteOne(clientSession: ClientSession, vararg filters: Bson?, deleteOptions: DeleteOptions = DeleteOptions()): DeleteResult

Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.deleteOneById(id: Any): DeleteResult
fun <T : Any> MongoCollection<T>.deleteOneById(clientSession: ClientSession, id: Any): DeleteResult

Removes at most one document from the id parameter. If no documents match, the collection is not modified.

Link copied to clipboard
fun <T : Any> FindIterable<T>.descendingSort(vararg properties: KProperty<*>): FindIterable<T>

Sets the sort criteria with specified descending properties to apply to the query.

Link copied to clipboard
fun <T> MongoIterable<T>.distinct(): List<T>

Returns a list containing only distinct elements from the given collection.

inline fun <TResult : Any> MongoCollection<*>.distinct(fieldName: String, filter: String = KMongoUtil.EMPTY_JSON): DistinctIterable<TResult>
inline fun <TResult : Any> MongoCollection<*>.distinct(clientSession: ClientSession, fieldName: String, filter: String = KMongoUtil.EMPTY_JSON): DistinctIterable<TResult>

Gets the distinct values of the specified field name.

inline fun <T : Any, TResult> MongoCollection<T>.distinct(field: KProperty1<T, TResult>, filter: Bson = EMPTY_BSON): DistinctIterable<TResult>
inline fun <T : Any, TResult> MongoCollection<T>.distinct(clientSession: ClientSession, field: KProperty1<T, TResult>, filter: Bson = EMPTY_BSON): DistinctIterable<TResult>

Gets the distinct values of the specified field.

Link copied to clipboard
inline fun <T, K> MongoIterable<T>.distinctBy(crossinline selector: (T) -> K): List<T>

Returns a list containing only elements from the given collection having distinct keys returned by the given selector function.

Link copied to clipboard
fun <T> MongoIterable<T>.drop(n: Int): List<T>

Returns a list containing all elements except first n elements.

Link copied to clipboard
inline fun <T : Any> MongoDatabase.dropCollection()

Drops the default collection of T (see getCollection).

Link copied to clipboard
fun <T : Any> MongoCollection<T>.dropIndex(keys: String)
fun <T : Any> MongoCollection<T>.dropIndex(clientSession: ClientSession, keys: String)

Drops the index given the keys used to create it.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.dropIndexOfKeys(json: String)
fun <T : Any> MongoCollection<T>.dropIndexOfKeys(clientSession: ClientSession, json: String)

Drops the index given the keys used to create it.

Link copied to clipboard
inline fun <T> MongoIterable<T>.dropWhile(crossinline predicate: (T) -> Boolean): List<T>

Returns a list containing all elements except first elements that satisfy the given predicate.

Link copied to clipboard
fun <T> MongoIterable<T>.elementAt(index: Int): T

Returns an element at the given index or throws an IndexOutOfBoundsException if the index is out of bounds of this collection.

Link copied to clipboard
fun <T> MongoIterable<T>.elementAtOrElse(index: Int, defaultValue: (Int) -> T): T

Returns an element at the given index or the result of calling the defaultValue function if the index is out of bounds of this collection.

Link copied to clipboard
fun <T> MongoIterable<T>.elementAtOrNull(index: Int): T?

Returns an element at the given index or null if the index is out of bounds of this collection.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.ensureIndex(keys: String, indexOptions: IndexOptions = IndexOptions()): String
fun <T : Any> MongoCollection<T>.ensureIndex(keys: Bson, indexOptions: IndexOptions = IndexOptions()): String
fun <T : Any> MongoCollection<T>.ensureIndex(clientSession: ClientSession, keys: String, indexOptions: IndexOptions = IndexOptions()): String
fun <T : Any> MongoCollection<T>.ensureIndex(clientSession: ClientSession, keys: Bson, 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.

fun <T : Any> MongoCollection<T>.ensureIndex(vararg properties: KProperty<*>, indexOptions: IndexOptions = IndexOptions()): String
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.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.ensureUniqueIndex(vararg properties: KProperty<*>, indexOptions: IndexOptions = IndexOptions()): String
fun <T : Any> MongoCollection<T>.ensureUniqueIndex(clientSession: ClientSession, vararg properties: KProperty<*>, indexOptions: IndexOptions = IndexOptions()): String

Create an IndexOptions.unique 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.

Link copied to clipboard
fun <T, R> MongoIterable<T>.evaluate(expression: Sequence<T>.() -> R): R

Evaluates the current MongoIterable given the expression of Sequences.

Link copied to clipboard
fun <T : Any> DistinctIterable<T>.filter(filter: String): DistinctIterable<T>
fun <T : Any> FindIterable<T>.filter(filter: String): FindIterable<T>

Sets the query filter to apply to the query.

inline fun <T> MongoIterable<T>.filter(crossinline predicate: (T) -> Boolean): List<T>

Returns a list containing only elements matching the given predicate.

Link copied to clipboard
inline fun <T> MongoIterable<T>.filterIndexed(crossinline predicate: (index: Int, T) -> Boolean): List<T>

Returns a list containing only elements matching the given predicate.

Link copied to clipboard
inline fun <T, C : MutableCollection<in T>> MongoIterable<T>.filterIndexedTo(destination: C, crossinline predicate: (index: Int, T) -> Boolean): C

Appends all elements matching the given predicate to the given destination.

Link copied to clipboard
inline fun <R> MongoIterable<*>.filterIsInstance(): List<R>

Returns a list containing all elements that are instances of specified type parameter R.

fun <R> MongoIterable<*>.filterIsInstance(klass: Class<R>): List<R>

Returns a list containing all elements that are instances of specified class.

Link copied to clipboard
inline fun <R, C : MutableCollection<in R>> MongoIterable<*>.filterIsInstanceTo(destination: C): C

Appends all elements that are instances of specified type parameter R to the given destination.

fun <C : MutableCollection<in R>, R> MongoIterable<*>.filterIsInstanceTo(destination: C, klass: Class<R>): C

Appends all elements that are instances of specified class to the given destination.

Link copied to clipboard
inline fun <T> MongoIterable<T>.filterNot(crossinline predicate: (T) -> Boolean): List<T>

Returns a list containing all elements not matching the given predicate.

Link copied to clipboard
fun <T : Any> MongoIterable<T?>.filterNotNull(): List<T>

Returns a list containing all elements that are not null.

Link copied to clipboard
fun <C : MutableCollection<in T>, T : Any> MongoIterable<T?>.filterNotNullTo(destination: C): C

Appends all elements that are not null to the given destination.

Link copied to clipboard
inline fun <T, C : MutableCollection<in T>> MongoIterable<T>.filterNotTo(destination: C, crossinline predicate: (T) -> Boolean): C

Appends all elements not matching the given predicate to the given destination.

Link copied to clipboard
inline fun <T, C : MutableCollection<in T>> MongoIterable<T>.filterTo(destination: C, crossinline predicate: (T) -> Boolean): C

Appends all elements matching the given predicate to the given destination.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.find(filter: String = KMongoUtil.EMPTY_JSON): FindIterable<T>
fun <T : Any> MongoCollection<T>.find(vararg filters: Bson?): FindIterable<T>
fun <T : Any> MongoCollection<T>.find(clientSession: ClientSession, filter: String = KMongoUtil.EMPTY_JSON): FindIterable<T>
fun <T : Any> MongoCollection<T>.find(clientSession: ClientSession, vararg filters: Bson?): FindIterable<T>

Finds all documents in the collection.

inline fun <T> MongoIterable<T>.find(crossinline predicate: (T) -> Boolean): T?

Returns the first element matching the given predicate, or null if no such element was found.

Link copied to clipboard
inline fun <T> MongoIterable<T>.findLast(crossinline predicate: (T) -> Boolean): T?

Returns the last element matching the given predicate, or null if no such element was found.

Link copied to clipboard
inline fun <T : Any> MongoCollection<T>.findOne(filters: () -> Bson): T?
fun <T : Any> MongoCollection<T>.findOne(filter: String = KMongoUtil.EMPTY_JSON): T?
fun <T : Any> MongoCollection<T>.findOne(filter: Bson): T?
inline fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, filters: () -> Bson): T?
fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, filter: String = KMongoUtil.EMPTY_JSON): T?
fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, filter: Bson): T?

Finds the first document that match the filter in the collection.

fun <T : Any> MongoCollection<T>.findOne(vararg filters: Bson?): T?
fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, vararg filters: Bson?): T?

Finds the first document that match the filters in the collection.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.findOneAndDelete(filter: String, options: FindOneAndDeleteOptions = FindOneAndDeleteOptions()): T?
fun <T : Any> MongoCollection<T>.findOneAndDelete(clientSession: ClientSession, filter: String, options: FindOneAndDeleteOptions = FindOneAndDeleteOptions()): T?

Atomically find a document and remove it.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.findOneAndReplace(filter: String, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): T?
fun <T : Any> MongoCollection<T>.findOneAndReplace(clientSession: ClientSession, filter: String, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): T?

Atomically find a document and replace it.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.findOneAndUpdate(filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?
fun <T : Any> MongoCollection<T>.findOneAndUpdate(clientSession: ClientSession, filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?

Atomically find a document and update it.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.findOneById(id: Any): T?
fun <T : Any> MongoCollection<T>.findOneById(clientSession: ClientSession, id: Any): T?

Finds the document that match the id parameter.

Link copied to clipboard
inline fun <T> MongoIterable<T>.first(crossinline predicate: (T) -> Boolean): T

Returns the first element matching the given predicate.

Link copied to clipboard
inline fun <T> MongoIterable<T>.firstOrNull(crossinline predicate: (T) -> Boolean): T?

Returns the first element matching the given predicate, or null if element was not found.

Link copied to clipboard
inline fun <T, R> MongoIterable<T>.flatMap(crossinline transform: (T) -> MongoIterable<R>): List<R>

Returns a single list of all elements yielded from results of transform function being invoked on each element of original collection.

Link copied to clipboard
inline fun <T, R, C : MutableCollection<in R>> MongoIterable<T>.flatMapTo(destination: C, crossinline transform: (T) -> MongoIterable<R>): C

Appends all elements yielded from results of transform function being invoked on each element of original collection, to the given destination.

Link copied to clipboard
fun <T> MongoIterable<Iterable<T>>.flatten(): List<T>

Returns a single list of all elements from all collections in the given collection.

Link copied to clipboard
inline fun <T, R> MongoIterable<T>.fold(initial: R, crossinline operation: (acc: R, T) -> R): R

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element.

Link copied to clipboard
inline fun <T, R> MongoIterable<T>.foldIndexed(initial: R, crossinline operation: (index: Int, acc: R, T) -> R): R

Accumulates value starting with initial value and applying operation from left to right to current accumulator value and each element with its index in the original collection.

Link copied to clipboard
inline fun <T> MongoIterable<T>.forEachIndexed(crossinline action: (index: Int, T) -> Unit)

Performs the given action on each element, providing sequential index with the element.

Link copied to clipboard
inline fun <T : Any> MongoDatabase.getCollection(): MongoCollection<T>
inline fun <T : Any> MongoDatabase.getCollection(collectionName: String): MongoCollection<T>

Gets a collection.

Link copied to clipboard
inline fun <T : Any> MongoDatabase.getCollectionOfName(collectionName: String): MongoCollection<T>

Gets a collection.

Link copied to clipboard
inline fun <T, K> MongoIterable<T>.groupBy(crossinline keySelector: (T) -> K): Map<K, List<T>>

Groups elements of the original collection by the key returned by the given keySelector function applied to each element and returns a map where each group key is associated with a list of corresponding elements.

inline fun <T, K, V> MongoIterable<T>.groupBy(crossinline keySelector: (T) -> K, crossinline valueTransform: (T) -> V): Map<K, List<V>>

Groups values returned by the valueTransform function applied to each element of the original collection by the key returned by the given keySelector function applied to the element and returns a map where each group key is associated with a list of corresponding values.

Link copied to clipboard
inline fun <T, K, M : MutableMap<in K, MutableList<T>>> MongoIterable<T>.groupByTo(destination: M, crossinline keySelector: (T) -> K): M

Groups elements of the original collection by the key returned by the given keySelector function applied to each element and puts to the destination map each group key associated with a list of corresponding elements.

inline fun <T, K, V, M : MutableMap<in K, MutableList<V>>> MongoIterable<T>.groupByTo(destination: M, crossinline keySelector: (T) -> K, crossinline valueTransform: (T) -> V): M

Groups values returned by the valueTransform function applied to each element of the original collection by the key returned by the given keySelector function applied to the element and puts to the destination map each group key associated with a list of corresponding values.

Link copied to clipboard
inline fun <T, K> MongoIterable<T>.groupingBy(crossinline keySelector: (T) -> K): Grouping<T, K>

Creates a Grouping source from a collection to be used later with one of group-and-fold operations using the specified keySelector function to extract a key from each element.

Link copied to clipboard
fun <T> MongoIterable<T>.indexOf(element: T): Int

Returns first index of element, or -1 if the collection does not contain element.

Link copied to clipboard
inline fun <T> MongoIterable<T>.indexOfFirst(crossinline predicate: (T) -> Boolean): Int

Returns index of the first element matching the given predicate, or -1 if the collection does not contain such element.

Link copied to clipboard
inline fun <T> MongoIterable<T>.indexOfLast(crossinline predicate: (T) -> Boolean): Int

Returns index of the last element matching the given predicate, or -1 if the collection does not contain such element.

Link copied to clipboard
inline fun <T : Any> MongoCollection<T>.insertOne(document: String, options: InsertOneOptions = InsertOneOptions()): InsertOneResult
inline fun <T : Any> MongoCollection<T>.insertOne(clientSession: ClientSession, document: String, options: InsertOneOptions = InsertOneOptions()): InsertOneResult

Inserts the provided document. If the document is missing an identifier, the driver should generate one.

Link copied to clipboard
infix fun <T> MongoIterable<T>.intersect(other: Iterable<T>): Set<T>

Returns a set containing all elements that are contained by both this set and the specified collection.

Link copied to clipboard
fun <T : Any, A : MutableCollection<in T>> MongoIterable<T>.into(target: A): A

KMongo 4/5 compatibility: the Java driver MongoIterable.into(target).

Link copied to clipboard
operator fun <T : Any> MongoIterable<T>.iterator(): MongoCursor<T>

KMongo 4/5 compatibility: the Java driver MongoIterable was an Iterable (for (x in col.find()) compiles) - the Kotlin driver MongoIterable is not.

Link copied to clipboard
fun <T, A : Appendable> MongoIterable<T>.joinTo(buffer: A, separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: (T) -> CharSequence? = null): A

Appends the string from all the elements separated using separator and using the given prefix and postfix if supplied.

Link copied to clipboard
fun <T> MongoIterable<T>.joinToString(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "", limit: Int = -1, truncated: CharSequence = "...", transform: (T) -> CharSequence? = null): String

Creates a string from all the elements separated using separator and using the given prefix and postfix if supplied.

Link copied to clipboard
fun <T> MongoIterable<T>.last(): T

Returns the last element.

inline fun <T> MongoIterable<T>.last(crossinline predicate: (T) -> Boolean): T

Returns the last element matching the given predicate.

Link copied to clipboard
fun <T> MongoIterable<T>.lastIndexOf(element: T): Int

Returns last index of element, or -1 if the collection does not contain element.

Link copied to clipboard
fun <T> MongoIterable<T>.lastOrNull(): T?

Returns the last element, or null if the collection is empty.

inline fun <T> MongoIterable<T>.lastOrNull(crossinline predicate: (T) -> Boolean): T?

Returns the last element matching the given predicate, or null if no such element was found.

Link copied to clipboard
fun <T : Any> ChangeStreamIterable<T>.listen(executor: ScheduledExecutorService? = null, delay: Long = 500, unit: TimeUnit = TimeUnit.MILLISECONDS, listener: (ChangeStreamDocument<T>) -> Unit): AutoCloseable

Listens change stream in an other thread.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.listenIndefinitely(pipeline: List<Bson> = emptyList(), fullDocument: FullDocument = FullDocument.DEFAULT, retryDelay: Duration = 1.seconds, maxRetryDelay: Duration = 1.minutes, onError: (Throwable) -> Unit = {}, configure: ChangeStreamIterable<T>.() -> ChangeStreamIterable<T> = { this }, listener: (ChangeStreamDocument<T>) -> Unit): AutoCloseable

Listens the changes of the collection indefinitely, in a (daemon) thread: a change stream that survives the errors and the invalidations.

Link copied to clipboard
inline fun <TResult : Any> MongoCollection<*>.listIndexes(): ListIndexesIterable<TResult>
inline fun <TResult : Any> MongoCollection<*>.listIndexes(clientSession: ClientSession): ListIndexesIterable<TResult>

Get all the indexes in this collection.

Link copied to clipboard
inline fun <TResult : Any> MongoCollection<*>.listTypedIndexes(): ListIndexesIterable<TResult>
inline fun <TResult : Any> MongoCollection<*>.listTypedIndexes(clientSession: ClientSession): ListIndexesIterable<TResult>

Get all the indexes in this collection.

Link copied to clipboard
fun <FROM : Any> lookup(from: MongoCollection<FROM>, localField: KProperty1<out Any, Any?>, foreignField: KProperty1<FROM, Any?>, newAs: KProperty1<out Any, Any?>): Bson

Creates a $lookup pipeline stage for the specified filter (Typesafe version)

Link copied to clipboard
inline fun <T, R> MongoIterable<T>.map(crossinline transform: (T) -> R): List<R>

Returns a list containing the results of applying the given transform function to each element in the original collection.

Link copied to clipboard
inline fun <T, R> MongoIterable<T>.mapIndexed(crossinline transform: (index: Int, T) -> R): List<R>

Returns a list containing the results of applying the given transform function to each element and its index in the original collection.

Link copied to clipboard
inline fun <T, R : Any> MongoIterable<T>.mapIndexedNotNull(crossinline transform: (index: Int, T) -> R?): List<R>

Returns a list containing only the non-null results of applying the given transform function to each element and its index in the original collection.

Link copied to clipboard
inline fun <T, R : Any, C : MutableCollection<in R>> MongoIterable<T>.mapIndexedNotNullTo(destination: C, crossinline transform: (index: Int, T) -> R?): C

Applies the given transform function to each element and its index in the original collection and appends only the non-null results to the given destination.

Link copied to clipboard
inline fun <T, R, C : MutableCollection<in R>> MongoIterable<T>.mapIndexedTo(destination: C, crossinline transform: (index: Int, T) -> R): C

Applies the given transform function to each element and its index in the original collection and appends the results to the given destination.

Link copied to clipboard
inline fun <T, R : Any> MongoIterable<T>.mapNotNull(crossinline transform: (T) -> R?): List<R>

Returns a list containing only the non-null results of applying the given transform function to each element in the original collection.

Link copied to clipboard
inline fun <T, R : Any, C : MutableCollection<in R>> MongoIterable<T>.mapNotNullTo(destination: C, crossinline transform: (T) -> R?): C

Applies the given transform function to each element in the original collection and appends only the non-null results to the given destination.

Link copied to clipboard
inline fun <T, R, C : MutableCollection<in R>> MongoIterable<T>.mapTo(destination: C, crossinline transform: (T) -> R): C

Applies the given transform function to each element of the original collection and appends the results to the given destination.

Link copied to clipboard
fun <T : Comparable<T>> MongoIterable<T>.max(): T?
fun MongoIterable<Double>.max(): Double?
fun MongoIterable<Float>.max(): Float?

Returns the largest element or null if there are no elements.

Link copied to clipboard
inline fun <T, R : Comparable<R>> MongoIterable<T>.maxBy(crossinline selector: (T) -> R): T?

Returns the first element yielding the largest value of the given function or null if there are no elements.

Link copied to clipboard
inline fun <T, R : Comparable<R>> MongoIterable<T>.maxByOrNull(crossinline selector: (T) -> R): T?

Returns the first element yielding the largest value of the given function or null if there are no elements.

Link copied to clipboard
fun <T : Comparable<T>> MongoIterable<T>.maxOrNull(): T?
fun MongoIterable<Double>.maxOrNull(): Double?
fun MongoIterable<Float>.maxOrNull(): Float?

Returns the largest element or null if there are no elements.

Link copied to clipboard
fun <T> MongoIterable<T>.maxWith(comparator: Comparator<in T>): T?

Returns the first element having the largest value according to the provided comparator or null if there are no elements.

Link copied to clipboard
fun <T> MongoIterable<T>.maxWithOrNull(comparator: Comparator<in T>): T?

Returns the first element having the largest value according to the provided comparator or null if there are no elements.

Link copied to clipboard
fun <T : Comparable<T>> MongoIterable<T>.min(): T?
fun MongoIterable<Double>.min(): Double?
fun MongoIterable<Float>.min(): Float?

Returns the smallest element or null if there are no elements.

Link copied to clipboard
inline fun <T, R : Comparable<R>> MongoIterable<T>.minBy(crossinline selector: (T) -> R): T?

Returns the first element yielding the smallest value of the given function or null if there are no elements.

Link copied to clipboard
inline fun <T, R : Comparable<R>> MongoIterable<T>.minByOrNull(crossinline selector: (T) -> R): T?

Returns the first element yielding the smallest value of the given function or null if there are no elements.

Link copied to clipboard
fun <T : Comparable<T>> MongoIterable<T>.minOrNull(): T?
fun MongoIterable<Double>.minOrNull(): Double?
fun MongoIterable<Float>.minOrNull(): Float?

Returns the smallest element or null if there are no elements.

Link copied to clipboard
operator fun <T> MongoIterable<T>.minus(element: T): List<T>

Returns a list containing all elements of the original collection without the first occurrence of the given element.

operator fun <T> MongoIterable<T>.minus(elements: Array<out T>): List<T>

Returns a list containing all elements of the original collection except the elements contained in the given elements array.

operator fun <T> MongoIterable<T>.minus(elements: Iterable<T>): List<T>

Returns a list containing all elements of the original collection except the elements contained in the given elements collection.

operator fun <T> MongoIterable<T>.minus(elements: Sequence<T>): List<T>

Returns a list containing all elements of the original collection except the elements contained in the given elements sequence.

Link copied to clipboard
inline fun <T> MongoIterable<T>.minusElement(element: T): List<T>

Returns a list containing all elements of the original collection without the first occurrence of the given element.

Link copied to clipboard
fun <T> MongoIterable<T>.minWith(comparator: Comparator<in T>): T?

Returns the first element having the smallest value according to the provided comparator or null if there are no elements.

Link copied to clipboard
fun <T> MongoIterable<T>.minWithOrNull(comparator: Comparator<in T>): T?

Returns the first element having the smallest value according to the provided comparator or null if there are no elements.

Link copied to clipboard
fun <T> MongoIterable<T>.none(): Boolean

Returns true if the collection has no elements.

inline fun <T> MongoIterable<T>.none(crossinline predicate: (T) -> Boolean): Boolean

Returns true if no elements match the given predicate.

Link copied to clipboard
inline fun <T> MongoIterable<T>.partition(crossinline predicate: (T) -> Boolean): Pair<List<T>, List<T>>

Splits the original collection into pair of lists, where first list contains elements for which predicate yielded true, while second list contains elements for which predicate yielded false.

Link copied to clipboard
operator fun <T> MongoIterable<T>.plus(element: T): List<T>

Returns a list containing all elements of the original collection and then the given element.

operator fun <T> MongoIterable<T>.plus(elements: Array<out T>): List<T>

Returns a list containing all elements of the original collection and then all elements of the given elements array.

operator fun <T> MongoIterable<T>.plus(elements: Iterable<T>): List<T>

Returns a list containing all elements of the original collection and then all elements of the given elements collection.

operator fun <T> MongoIterable<T>.plus(elements: Sequence<T>): List<T>

Returns a list containing all elements of the original collection and then all elements of the given elements sequence.

Link copied to clipboard
inline fun <T> MongoIterable<T>.plusElement(element: T): List<T>

Returns a list containing all elements of the original collection and then the given element.

Link copied to clipboard
fun <T : Any> FindIterable<T>.projection(projection: String): FindIterable<T>
fun <T : Any> FindIterable<T>.projection(vararg projections: KProperty<*>): FindIterable<T>

Sets a document describing the fields to return for all matching documents.

inline fun <T : Any, F> MongoCollection<T>.projection(property: KProperty<F>, query: Bson = EMPTY_BSON, options: (FindIterable<SingleProjection<F>>) -> FindIterable<SingleProjection<F>> = { it }): MongoIterable<F?>
inline fun <T : Any, F> MongoCollection<T>.projection(clientSession: ClientSession, property: KProperty<F>, query: Bson = EMPTY_BSON, options: (FindIterable<SingleProjection<F>>) -> FindIterable<SingleProjection<F>> = { it }): MongoIterable<F?>

Returns the specified field for all matching documents.

inline fun <T : Any, F1, F2> MongoCollection<T>.projection(property1: KProperty<F1>, property2: KProperty<F2>, query: Bson = EMPTY_BSON, options: (FindIterable<PairProjection<F1, F2>>) -> FindIterable<PairProjection<F1, F2>> = { it }): MongoIterable<Pair<F1?, F2?>>
inline fun <T : Any, F1, F2> MongoCollection<T>.projection(clientSession: ClientSession, property1: KProperty<F1>, property2: KProperty<F2>, query: Bson = EMPTY_BSON, options: (FindIterable<PairProjection<F1, F2>>) -> FindIterable<PairProjection<F1, F2>> = { it }): MongoIterable<Pair<F1?, F2?>>

Returns the specified two fields for all matching documents.

inline fun <T : Any, F1, F2, F3> MongoCollection<T>.projection(property1: KProperty<F1>, property2: KProperty<F2>, property3: KProperty<F3>, query: Bson = EMPTY_BSON, options: (FindIterable<TripleProjection<F1, F2, F3>>) -> FindIterable<TripleProjection<F1, F2, F3>> = { it }): MongoIterable<Triple<F1?, F2?, F3?>>
inline fun <T : Any, F1, F2, F3> MongoCollection<T>.projection(clientSession: ClientSession, property1: KProperty<F1>, property2: KProperty<F2>, property3: KProperty<F3>, query: Bson = EMPTY_BSON, options: (FindIterable<TripleProjection<F1, F2, F3>>) -> FindIterable<TripleProjection<F1, F2, F3>> = { it }): MongoIterable<Triple<F1?, F2?, F3?>>

Returns the specified three fields for all matching documents.

Link copied to clipboard
inline fun <S, T : S> MongoIterable<T>.reduce(crossinline operation: (acc: S, T) -> S): S

Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element.

Link copied to clipboard
inline fun <S, T : S> MongoIterable<T>.reduceIndexed(crossinline operation: (index: Int, acc: S, T) -> S): S

Accumulates value starting with the first element and applying operation from left to right to current accumulator value and each element with its index in the original collection.

Link copied to clipboard
inline fun <T : Any> MongoCollection<T>.replaceOne(replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult
inline fun <T : Any> MongoCollection<T>.replaceOne(clientSession: ClientSession, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.replaceOne(filter: String, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.replaceOne(clientSession: ClientSession, filter: String, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult

Replace a document in the collection according to the specified arguments.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.replaceOneById(id: Any, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.replaceOneById(clientSession: ClientSession, id: Any, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult

Replace a document in the collection according to the specified arguments.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.replaceOneWithFilter(filter: Bson, replacement: T, replaceOptions: ReplaceOptions = ReplaceOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.replaceOneWithFilter(clientSession: ClientSession, filter: Bson, replacement: T, replaceOptions: ReplaceOptions = ReplaceOptions()): UpdateResult

Replace a document in the collection according to the specified arguments. Same than MongoCollection.replaceOne but ensure that any _id present in replacement is removed to avoid MongoWriteException such as: "After applying the update, the (immutable) field '_id' was found to have been altered to _id"

Link copied to clipboard
fun <T : Any> MongoIterable<T?>.requireNoNulls(): Iterable<T>
Link copied to clipboard
fun <T> MongoIterable<T>.reversed(): List<T>

Returns a list with elements in reversed order.

Link copied to clipboard
inline fun <TResult : Any> MongoDatabase.runCommand(command: String): TResult
inline fun <TResult : Any> MongoDatabase.runCommand(clientSession: ClientSession, command: String): TResult
inline fun <TResult : Any> MongoDatabase.runCommand(command: String, readPreference: ReadPreference): TResult
inline fun <TResult : Any> MongoDatabase.runCommand(clientSession: ClientSession, command: String, readPreference: ReadPreference): TResult

Executes the given command in the context of the current database with the given read preference.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.save(document: T): UpdateResult?
fun <T : Any> MongoCollection<T>.save(clientSession: ClientSession, document: T): UpdateResult?

Save the document. If the document has no id field, or if the document has a null id value, insert the document. Otherwise, call replaceOneById with upsert true.

Link copied to clipboard
fun <T> MongoIterable<T>.shuffled(): List<T>

Returns a new list with the elements of this list randomly shuffled.

fun <T> MongoIterable<T>.shuffled(random: Random): List<T>

Returns a new list with the elements of this list randomly shuffled using the specified random instance as the source of randomness.

Link copied to clipboard
fun <T> MongoIterable<T>.single(): T

Returns the single element, or throws an exception if the collection is empty or has more than one element.

inline fun <T> MongoIterable<T>.single(crossinline predicate: (T) -> Boolean): T

Returns the single element matching the given predicate, or throws exception if there is no or more than one matching element.

Link copied to clipboard
fun <T> MongoIterable<T>.singleOrNull(): T?

Returns single element, or null if the collection is empty or has more than one element.

inline fun <T> MongoIterable<T>.singleOrNull(crossinline predicate: (T) -> Boolean): T?

Returns the single element matching the given predicate, or null if element was not found or more than one element was found.

Link copied to clipboard
fun <T : Any> FindIterable<T>.sort(sort: String): FindIterable<T>

Sets the sort criteria to apply to the query.

Link copied to clipboard
fun <T : Comparable<T>> MongoIterable<T>.sorted(): List<T>

Returns a list of all elements sorted according to their natural sort order.

Link copied to clipboard
inline fun <T, R : Comparable<R>> MongoIterable<T>.sortedBy(crossinline selector: (T) -> R?): List<T>

Returns a list of all elements sorted according to natural sort order of the value returned by specified selector function.

Link copied to clipboard
inline fun <T, R : Comparable<R>> MongoIterable<T>.sortedByDescending(crossinline selector: (T) -> R?): List<T>

Returns a list of all elements sorted descending according to natural sort order of the value returned by specified selector function.

Link copied to clipboard
fun <T : Comparable<T>> MongoIterable<T>.sortedDescending(): List<T>

Returns a list of all elements sorted descending according to their natural sort order.

Link copied to clipboard
fun <T> MongoIterable<T>.sortedWith(comparator: Comparator<in T>): List<T>

Returns a list of all elements sorted according to the specified comparator.

Link copied to clipboard
infix fun <T> MongoIterable<T>.subtract(other: Iterable<T>): Set<T>

Returns a set containing all elements that are contained by this collection and not contained by the specified collection.

Link copied to clipboard
@JvmName(name = "sumOfByte")
fun MongoIterable<Byte>.sum(): Int
@JvmName(name = "sumOfDouble")
fun MongoIterable<Double>.sum(): Double
@JvmName(name = "sumOfFloat")
fun MongoIterable<Float>.sum(): Float
@JvmName(name = "sumOfInt")
fun MongoIterable<Int>.sum(): Int
@JvmName(name = "sumOfLong")
fun MongoIterable<Long>.sum(): Long
@JvmName(name = "sumOfShort")
fun MongoIterable<Short>.sum(): Int

Returns the sum of all elements in the collection.

Link copied to clipboard
inline fun <T> MongoIterable<T>.sumBy(crossinline selector: (T) -> Int): Int

Returns the sum of all values produced by selector function applied to each element in the collection.

Link copied to clipboard
inline fun <T> MongoIterable<T>.sumByDouble(crossinline selector: (T) -> Double): Double

Returns the sum of all values produced by selector function applied to each element in the collection.

Link copied to clipboard
fun <T> MongoIterable<T>.take(n: Int): List<T>

Returns a list containing first n elements.

Link copied to clipboard
inline fun <T> MongoIterable<T>.takeWhile(crossinline predicate: (T) -> Boolean): List<T>

Returns a list containing first elements satisfying the given predicate.

Link copied to clipboard
fun <T, C : MutableCollection<in T>> MongoIterable<T>.toCollection(destination: C): C

Appends all elements to the given destination collection.

Link copied to clipboard
fun <T> MongoIterable<T>.toHashSet(): HashSet<T>

Returns a HashSet of all elements.

Link copied to clipboard
fun <T> MongoIterable<T>.toList(): List<T>

Returns a List containing all elements.

Link copied to clipboard
fun <K, V> MongoIterable<Pair<K, V>>.toMap(): Map<K, V>

Returns a new map containing all key-value pairs from the given collection of pairs.

fun <K, V, M : MutableMap<in K, in V>> MongoIterable<Pair<K, V>>.toMap(destination: M): M

Populates and returns the destination mutable map with key-value pairs from the given collection of pairs.

Link copied to clipboard
fun <T> MongoIterable<T>.toMutableList(): MutableList<T>

Returns a MutableList filled with all elements of this collection.

Link copied to clipboard
fun <T> MongoIterable<T>.toMutableSet(): MutableSet<T>

Returns a mutable set containing all distinct elements from the given collection.

Link copied to clipboard
fun <T> MongoIterable<T>.toSet(): Set<T>

Returns a Set of all elements.

Link copied to clipboard
fun <T : Comparable<T>> MongoIterable<T>.toSortedSet(): SortedSet<T>
fun <T> MongoIterable<T>.toSortedSet(comparator: Comparator<in T>): SortedSet<T>

Returns a SortedSet of all elements.

Link copied to clipboard
infix fun <T> MongoIterable<T>.union(other: Iterable<T>): Set<T>

Returns a set containing all distinct elements from both collections.

Link copied to clipboard
fun <T, R> MongoIterable<Pair<T, R>>.unzip(): Pair<List<T>, List<R>>

Returns a pair of lists, where first list is built from the first values of each pair from this collection, second list is built from the second values of each pair from this collection.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.updateMany(filter: String, update: String, updateOptions: UpdateOptions = UpdateOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.updateMany(filter: Bson, vararg updates: SetTo<*>, updateOptions: UpdateOptions = UpdateOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.updateMany(clientSession: ClientSession, filter: String, update: String, updateOptions: UpdateOptions = UpdateOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.updateMany(clientSession: ClientSession, filter: Bson, vararg updates: SetTo<*>, updateOptions: UpdateOptions = UpdateOptions()): UpdateResult

Update all documents in the collection according to the specified arguments.

Link copied to clipboard
inline fun <T : Any> MongoCollection<T>.updateOne(target: T, options: UpdateOptions = UpdateOptions(), updateOnlyNotNullProperties: Boolean = UpdateConfiguration.updateOnlyNotNullProperties): UpdateResult
fun <T : Any> MongoCollection<T>.updateOne(filter: String, update: String, options: UpdateOptions = UpdateOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.updateOne(filter: Bson, vararg updates: SetTo<*>, updateOptions: UpdateOptions = UpdateOptions()): UpdateResult
inline fun <T : Any> MongoCollection<T>.updateOne(clientSession: ClientSession, target: T, options: UpdateOptions = UpdateOptions(), updateOnlyNotNullProperties: Boolean = UpdateConfiguration.updateOnlyNotNullProperties): UpdateResult
fun <T : Any> MongoCollection<T>.updateOne(clientSession: ClientSession, filter: String, update: String, options: UpdateOptions = UpdateOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.updateOne(clientSession: ClientSession, filter: Bson, vararg updates: SetTo<*>, updateOptions: UpdateOptions = UpdateOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.updateOne(filter: String, update: Any, options: UpdateOptions = UpdateOptions(), updateOnlyNotNullProperties: Boolean = UpdateConfiguration.updateOnlyNotNullProperties): UpdateResult
fun <T : Any> MongoCollection<T>.updateOne(filter: Bson, target: Any, options: UpdateOptions = UpdateOptions(), updateOnlyNotNullProperties: Boolean = UpdateConfiguration.updateOnlyNotNullProperties): UpdateResult
fun <T : Any> MongoCollection<T>.updateOne(clientSession: ClientSession, filter: String, update: Any, options: UpdateOptions = UpdateOptions(), updateOnlyNotNullProperties: Boolean = UpdateConfiguration.updateOnlyNotNullProperties): UpdateResult
fun <T : Any> MongoCollection<T>.updateOne(clientSession: ClientSession, filter: Bson, target: Any, options: UpdateOptions = UpdateOptions(), updateOnlyNotNullProperties: Boolean = UpdateConfiguration.updateOnlyNotNullProperties): UpdateResult

Update a single document in the collection according to the specified arguments.

Link copied to clipboard
fun <T : Any> MongoCollection<T>.updateOneById(id: Any, vararg updates: SetTo<*>, options: UpdateOptions = UpdateOptions()): UpdateResult
fun <T : Any> MongoCollection<T>.updateOneById(id: Any, update: Any, options: UpdateOptions = UpdateOptions(), updateOnlyNotNullProperties: Boolean = UpdateConfiguration.updateOnlyNotNullProperties): UpdateResult
fun <T : Any> MongoCollection<T>.updateOneById(clientSession: ClientSession, id: Any, update: Any, options: UpdateOptions = UpdateOptions(), updateOnlyNotNullProperties: Boolean = UpdateConfiguration.updateOnlyNotNullProperties): UpdateResult

Update a single document in the collection according to the specified arguments.

Link copied to clipboard
fun <T, R> MongoIterable<T>.useCursor(block: (Iterable<T>) -> R): R

Iterates over the MongoIterable cursor (the cursor is closed after the call).

Link copied to clipboard
fun <T> MongoIterable<T>.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false): List<List<T>>

Returns a list of snapshots of the window of the given size sliding along this collection with the given step, where each snapshot is a list.

fun <T, R> MongoIterable<T>.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false, transform: (List<T>) -> R): List<R>

Returns a list of results of applying the given transform function to an each list representing a view over the window of the given size sliding along this collection with the given step.

Link copied to clipboard
inline fun <NewTDocument : Any> MongoCollection<*>.withDocumentClass(): MongoCollection<NewTDocument>

KMongo 4/5 compatibility: withDocumentClass was a KMongo extension, it is now a member of the official driver collection - this declaration only keeps import org.litote.kmongo.withDocumentClass valid: remove the import.

Link copied to clipboard
fun <T> MongoIterable<T>.withIndex(): List<IndexedValue<T>>

Returns a MongoIterable of IndexedValue (the index is computed at iteration time).

Link copied to clipboard
fun <T : Any> MongoCollection<T>.withKMongo(): MongoCollection<T>

Returns a MongoCollection with a KMongo codec.

fun MongoDatabase.withKMongo(): MongoDatabase

Returns a MongoDatabase with a KMongo codec.

Link copied to clipboard
infix fun <T, R> MongoIterable<T>.zip(other: Array<out R>): List<Pair<T, R>>

Returns a list of pairs built from the elements of this collection and the other array with the same index. The returned list has length of the shortest collection.

infix fun <T, R> MongoIterable<T>.zip(other: Iterable<R>): List<Pair<T, R>>

Returns a list of pairs built from the elements of this collection and other collection with the same index. The returned list has length of the shortest collection.

inline fun <T, R, V> MongoIterable<T>.zip(other: Array<out R>, crossinline transform: (a: T, b: R) -> V): List<V>

Returns a list of values built from the elements of this collection and the other array with the same index using the provided transform function applied to each pair of elements. The returned list has length of the shortest collection.

inline fun <T, R, V> MongoIterable<T>.zip(other: Iterable<R>, crossinline transform: (a: T, b: R) -> V): List<V>

Returns a list of values built from the elements of this collection and the other collection with the same index using the provided transform function applied to each pair of elements. The returned list has length of the shortest collection.

Link copied to clipboard
fun <T> MongoIterable<T>.zipWithNext(): List<Pair<T, T>>

Returns a list of pairs of each two adjacent elements in this collection.

inline fun <T, R> MongoIterable<T>.zipWithNext(crossinline transform: (a: T, b: T) -> R): List<R>

Returns a list containing the results of applying the given transform function to an each pair of two adjacent elements in this collection.