kmongo / org.litote.kmongo.reactor / com.mongodb.reactivestreams.client.MongoCollection

Extensions for com.mongodb.reactivestreams.client.MongoCollection

aggregate

Aggregates documents according to the specified aggregation pipeline. If the pipeline ends with a $out stage, the returned iterable will be a query of the collection that the aggregation was written to. Note that in this case the pipeline will be executed even if the iterable is never iterated.

fun <TResult : Any> MongoCollection<*>.aggregate(vararg pipeline: String): AggregateFlux<TResult>
fun <TResult : Any> MongoCollection<*>.aggregate(clientSession: ClientSession, vararg pipeline: String): AggregateFlux<TResult>
fun <TResult : Any> MongoCollection<*>.aggregate(vararg pipeline: Bson): AggregateFlux<TResult>
fun <TResult : Any> MongoCollection<*>.aggregate(clientSession: ClientSession, vararg pipeline: Bson): AggregateFlux<TResult>

bulkWrite

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

fun <T : Any> MongoCollection<T>.bulkWrite(vararg requests: String, options: BulkWriteOptions = BulkWriteOptions()): Mono<BulkWriteResult>
fun <T : Any> MongoCollection<T>.bulkWrite(clientSession: ClientSession, vararg requests: String, options: BulkWriteOptions = BulkWriteOptions()): Mono<BulkWriteResult>
fun <T : Any> MongoCollection<T>.bulkWrite(vararg requests: WriteModel<T>, options: BulkWriteOptions = BulkWriteOptions()): Mono<BulkWriteResult>
fun <T : Any> MongoCollection<T>.bulkWrite(clientSession: ClientSession, vararg requests: WriteModel<T>, options: BulkWriteOptions = BulkWriteOptions()): Mono<BulkWriteResult>

countDocuments

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

fun <T> MongoCollection<T>.countDocuments(filter: String, options: CountOptions = CountOptions()): Mono<Long>
fun <T> MongoCollection<T>.countDocuments(clientSession: ClientSession, filter: String, options: CountOptions = CountOptions()): Mono<Long>

createIndex

Creates an index. If successful, the callback will be executed with the name of the created index as the result.

fun <T> MongoCollection<T>.createIndex(key: String, options: IndexOptions = IndexOptions()): Mono<String>
fun <T> MongoCollection<T>.createIndex(clientSession: ClientSession, key: String, options: IndexOptions = IndexOptions()): Mono<String>

deleteMany

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

fun <T> MongoCollection<T>.deleteMany(filter: String, options: DeleteOptions = DeleteOptions()): Mono<DeleteResult>
fun <T> MongoCollection<T>.deleteMany(clientSession: ClientSession, filter: String, options: DeleteOptions = DeleteOptions()): Mono<DeleteResult>
fun <T> MongoCollection<T>.deleteMany(vararg filters: Bson?, options: DeleteOptions = DeleteOptions()): Mono<DeleteResult>
fun <T> MongoCollection<T>.deleteMany(clientSession: ClientSession, vararg filters: Bson?, options: DeleteOptions = DeleteOptions()): Mono<DeleteResult>

deleteOne

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

fun <T> MongoCollection<T>.deleteOne(filter: String): Mono<DeleteResult>
fun <T> MongoCollection<T>.deleteOne(clientSession: ClientSession, filter: String): Mono<DeleteResult>
fun <T> MongoCollection<T>.deleteOne(vararg filters: Bson?): Mono<DeleteResult>
fun <T> MongoCollection<T>.deleteOne(clientSession: ClientSession, vararg filters: Bson?): Mono<DeleteResult>

deleteOneById

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

fun <T> MongoCollection<T>.deleteOneById(id: Any): Mono<DeleteResult>
fun <T> MongoCollection<T>.deleteOneById(clientSession: ClientSession, id: Any): Mono<DeleteResult>

distinct

Gets the distinct values of the specified field name.

fun <TResult : Any> MongoCollection<*>.distinct(fieldName: String): DistinctFlux<TResult>
fun <TResult : Any> MongoCollection<*>.distinct(clientSession: ClientSession, fieldName: String): DistinctFlux<TResult>
fun <TResult : Any> MongoCollection<*>.distinct(fieldName: String, filter: String): DistinctFlux<TResult>
fun <TResult : Any> MongoCollection<*>.distinct(clientSession: ClientSession, fieldName: String, filter: String): DistinctFlux<TResult>
fun <T : Any, TResult : Any> MongoCollection<*>.distinct(field: KProperty1<T, TResult>, filter: Bson = EMPTY_BSON): DistinctFlux<TResult>
fun <T : Any, TResult : Any> MongoCollection<*>.distinct(clientSession: ClientSession, field: KProperty1<T, TResult>, filter: Bson = EMPTY_BSON): DistinctFlux<TResult>

ensureIndex

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> MongoCollection<T>.ensureIndex(keys: String, indexOptions: IndexOptions = IndexOptions()): Mono<Void>
fun <T> MongoCollection<T>.ensureIndex(clientSession: ClientSession, keys: String, indexOptions: IndexOptions = IndexOptions()): Mono<Void>
fun <T> MongoCollection<T>.ensureIndex(keys: Bson, indexOptions: IndexOptions = IndexOptions()): Mono<Void>
fun <T> MongoCollection<T>.ensureIndex(clientSession: ClientSession, keys: Bson, indexOptions: IndexOptions = IndexOptions()): Mono<Void>
fun <T> MongoCollection<T>.ensureIndex(vararg properties: KProperty<*>, indexOptions: IndexOptions = IndexOptions()): Mono<Void>
fun <T> MongoCollection<T>.ensureIndex(clientSession: ClientSession, vararg properties: KProperty<*>, indexOptions: IndexOptions = IndexOptions()): Mono<Void>

ensureUniqueIndex

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.

fun <T> MongoCollection<T>.ensureUniqueIndex(vararg properties: KProperty<*>, indexOptions: IndexOptions = IndexOptions()): Mono<Void>
fun <T> MongoCollection<T>.ensureUniqueIndex(clientSession: ClientSession, vararg properties: KProperty<*>, indexOptions: IndexOptions = IndexOptions()): Mono<Void>

find

Finds all documents that match the filter in the collection.

fun <T : Any> MongoCollection<T>.find(filter: String): FindFlux<T>
fun <T : Any> MongoCollection<T>.find(clientSession: ClientSession, filter: String): FindFlux<T>

Finds all documents that match the filters in the collection.

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

findOne

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

fun <T : Any> MongoCollection<T>.findOne(filter: String = KMongoUtil.EMPTY_JSON): Mono<T>
fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, filter: String = KMongoUtil.EMPTY_JSON): Mono<T>
fun <T : Any> MongoCollection<T>.findOne(filter: Bson): Mono<T>
fun <T : Any> MongoCollection<T>.findOne(clientSession: ClientSession, filter: Bson): Mono<T>

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

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

findOneAndDelete

Atomically find a document and remove it.

fun <T : Any> MongoCollection<T>.findOneAndDelete(filter: String, options: FindOneAndDeleteOptions = FindOneAndDeleteOptions()): Mono<T>
fun <T : Any> MongoCollection<T>.findOneAndDelete(clientSession: ClientSession, filter: String, options: FindOneAndDeleteOptions = FindOneAndDeleteOptions()): Mono<T>

findOneAndReplace

Atomically find a document and replace it.

fun <T> MongoCollection<T>.findOneAndReplace(filter: String, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): Mono<T>
fun <T> MongoCollection<T>.findOneAndReplace(clientSession: ClientSession, filter: String, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): Mono<T>

findOneAndUpdate

Atomically find a document and update it.

fun <T : Any> MongoCollection<T>.findOneAndUpdate(filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): Mono<T>
fun <T : Any> MongoCollection<T>.findOneAndUpdate(clientSession: ClientSession, filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): Mono<T>

findOneById

Finds the document that match the id parameter.

fun <T : Any> MongoCollection<T>.findOneById(id: Any): Mono<T>
fun <T : Any> MongoCollection<T>.findOneById(clientSession: ClientSession, id: Any): Mono<T>

insert

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

fun <T : Any> MongoCollection<T>.insert(document: T, options: InsertOneOptions = InsertOneOptions()): Mono<Void>

insertOne

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

fun <T : Any> MongoCollection<T>.insertOne(document: String, options: InsertOneOptions = InsertOneOptions()): Mono<Void>
fun <T : Any> MongoCollection<T>.insertOne(clientSession: ClientSession, document: String, options: InsertOneOptions = InsertOneOptions()): Mono<Void>

listTypedIndexes

Get all the indexes in this collection.

fun <TResult : Any> MongoCollection<*>.listTypedIndexes(): ListIndexesFlux<TResult>
fun <TResult : Any> MongoCollection<*>.listTypedIndexes(clientSession: ClientSession): ListIndexesFlux<TResult>

mapReduceTyped

Aggregates documents according to the specified map-reduce function.

fun <TResult : Any> MongoCollection<*>.mapReduceTyped(mapFunction: String, reduceFunction: String): MapReduceFlux<TResult>
fun <TResult : Any> MongoCollection<*>.mapReduceTyped(clientSession: ClientSession, mapFunction: String, reduceFunction: String): MapReduceFlux<TResult>

replaceOne

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

fun <T : Any> MongoCollection<T>.replaceOne(replacement: T, options: ReplaceOptions = ReplaceOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.replaceOne(clientSession: ClientSession, replacement: T, options: ReplaceOptions = ReplaceOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.replaceOne(filter: String, replacement: T, options: ReplaceOptions = ReplaceOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.replaceOne(clientSession: ClientSession, filter: String, replacement: T, options: ReplaceOptions = ReplaceOptions()): Mono<UpdateResult>

replaceOneById

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

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

replaceOneWithoutId

Replace a document in the collection according to the specified arguments. The id of the provided document is not used, in order to avoid updated id error. You may have to use UpdateResult.getUpsertedId in order to retrieve the generated id.

fun <T : Any> MongoCollection<T>.replaceOneWithoutId(filter: Bson, replacement: T, options: ReplaceOptions = ReplaceOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.replaceOneWithoutId(clientSession: ClientSession, filter: Bson, replacement: T, options: ReplaceOptions = ReplaceOptions()): Mono<UpdateResult>

save

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.

fun <T : Any> MongoCollection<T>.save(document: T): Mono<Void>
fun <T : Any> MongoCollection<T>.save(clientSession: ClientSession, document: T): Mono<Void>

updateMany

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

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

updateOne

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

fun <T> MongoCollection<T>.updateOne(filter: String, update: String, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>
fun <T> MongoCollection<T>.updateOne(clientSession: ClientSession, filter: String, update: String, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.updateOne(filter: String, target: T, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.updateOne(clientSession: ClientSession, filter: String, target: T, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.updateOne(filter: Bson, target: T, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.updateOne(clientSession: ClientSession, filter: Bson, target: T, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.updateOne(target: T, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>
fun <T : Any> MongoCollection<T>.updateOne(clientSession: ClientSession, target: T, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>

updateOneById

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

fun <T> MongoCollection<T>.updateOneById(id: Any, update: Any, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>
fun <T> MongoCollection<T>.updateOneById(clientSession: ClientSession, id: Any, update: Any, options: UpdateOptions = UpdateOptions()): Mono<UpdateResult>

withDocumentClass

Create a new MongoCollection instance with a different default class to cast any documents returned from the database into..

fun <NewTDocument : Any> MongoCollection<*>.withDocumentClass(): ReactorMongoCollection<NewTDocument>