kmongo / org.litote.kmongo.reactivestreams / 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): AggregatePublisher<TResult>
fun <TResult : Any> MongoCollection<*>.aggregate(vararg pipeline: Bson): AggregatePublisher<TResult>

bulkWrite

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

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

countDocuments

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

fun <T> MongoCollection<T>.countDocuments(filter: String): Publisher<Long>
fun <T> MongoCollection<T>.countDocuments(filter: String, options: CountOptions): Publisher<Long>

createIndex

Creates an index.

fun <T> MongoCollection<T>.createIndex(key: String): Publisher<String>
fun <T> MongoCollection<T>.createIndex(key: String, options: IndexOptions): Publisher<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()): Publisher<DeleteResult>
fun <T> MongoCollection<T>.deleteMany(vararg filters: Bson?, options: DeleteOptions = DeleteOptions()): Publisher<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): Publisher<DeleteResult>
fun <T> MongoCollection<T>.deleteOne(vararg filters: Bson?): Publisher<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): Publisher<DeleteResult>

distinct

Gets the distinct values of the specified field name.

fun <TResult : Any> MongoCollection<*>.distinct(fieldName: String): DistinctPublisher<TResult>
fun <TResult : Any> MongoCollection<*>.distinct(fieldName: String, filter: String): DistinctPublisher<TResult>

Gets the distinct values of the specified field.

fun <T : Any, TResult> MongoCollection<T>.distinct(field: KProperty1<T, TResult>, filter: Bson = EMPTY_BSON): DistinctPublisher<TResult>

dropIndexOfKeys

Drops the index given the keys used to create it.

fun <T> MongoCollection<T>.dropIndexOfKeys(keys: String): Publisher<Void>

find

Finds all documents that match the filter in the collection.

fun <T> MongoCollection<T>.find(filter: String): FindPublisher<T>

Finds all documents in the collection.

fun <T> MongoCollection<T>.find(vararg filters: Bson?): FindPublisher<T>

findOne

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

fun <T> MongoCollection<T>.findOne(filter: String = KMongoUtil.EMPTY_JSON): Publisher<T>
fun <T> MongoCollection<T>.findOne(filter: Bson): Publisher<T>

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

fun <T> MongoCollection<T>.findOne(vararg filters: Bson?): Publisher<T>

findOneAndDelete

Atomically find a document and remove it.

fun <T> MongoCollection<T>.findOneAndDelete(filter: String, options: FindOneAndDeleteOptions = FindOneAndDeleteOptions()): Publisher<T>

findOneAndReplace

Atomically find a document and replace it.

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

findOneAndUpdate

Atomically find a document and update it.

fun <T> MongoCollection<T>.findOneAndUpdate(filter: String, update: String, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): Publisher<T>

findOneById

Finds the document that match the id parameter.

fun <T> MongoCollection<T>.findOneById(id: Any): Publisher<T>

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): Publisher<InsertOneResult>
fun <T : Any> MongoCollection<T>.insertOne(document: String, options: InsertOneOptions): Publisher<InsertOneResult>

listTypedIndexes

Get all the indexes in this collection.

fun <TResult : Any> MongoCollection<*>.listTypedIndexes(): ListIndexesPublisher<TResult>

mapReduce

Aggregates documents according to the specified map-reduce function.

fun <TResult : Any> MongoCollection<*>.mapReduce(mapFunction: String, reduceFunction: String): MapReducePublisher<TResult>

mapReduceWith

Aggregates documents according to the specified map-reduce function.

fun <TResult : Any> MongoCollection<*>.mapReduceWith(mapFunction: String, reduceFunction: String): MapReducePublisher<TResult>

projection

Returns the specified field for all matching documents.

fun <T, F> MongoCollection<T>.projection(property: KProperty<F>, query: Bson = EMPTY_BSON, options: (FindPublisher<SingleProjection<F>>) -> FindPublisher<SingleProjection<F>> = { it }): FindPublisher<F>

Returns the specified two fields for all matching documents.

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

Returns the specified three fields for all matching documents.

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

replaceOne

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

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

replaceOneById

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

fun <T : Any> MongoCollection<T>.replaceOneById(id: Any, replacement: T): Publisher<UpdateResult>
fun <T : Any> MongoCollection<T>.replaceOneById(id: Any, replacement: T, options: ReplaceOptions): Publisher<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()): Publisher<UpdateResult>
fun <T : Any> MongoCollection<T>.replaceOneWithoutId(filter: String, replacement: T, options: ReplaceOptions = ReplaceOptions()): Publisher<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): Publisher<*>

updateMany

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

fun <T> MongoCollection<T>.updateMany(filter: String, update: String, updateOptions: UpdateOptions = UpdateOptions()): Publisher<UpdateResult>
fun <T : Any> MongoCollection<T>.updateMany(filter: Bson, vararg updates: SetTo<*>, updateOptions: UpdateOptions = UpdateOptions()): Publisher<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()): Publisher<UpdateResult>
fun <T> MongoCollection<T>.updateOne(filter: String, update: Any, options: UpdateOptions = UpdateOptions(), updateOnlyNotNullProperties: Boolean = UpdateConfiguration.updateOnlyNotNullProperties): Publisher<UpdateResult>
fun <T> MongoCollection<T>.updateOne(filter: Bson, target: Any, options: UpdateOptions = UpdateOptions()): Publisher<UpdateResult>
fun <T : Any> MongoCollection<T>.updateOne(target: T, options: UpdateOptions = UpdateOptions()): Publisher<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()): Publisher<UpdateResult>

watchIndefinitely

Watches collection changes. Open a new stream if an invalidate event or drop database event occurs.

fun <T : Any> MongoCollection<T>.watchIndefinitely(fullDocument: FullDocument = FullDocument.DEFAULT, subscribeListener: () -> Unit = {}, errorListener: (Throwable) -> Unit = {}, reopenListener: () -> Unit = {}, reopenDelayInMS: Long = 5000, listener: (ChangeStreamDocument<T>) -> Unit): Unit

Watches collection changes. Open a new stream if an invalidate event occurs. The basic idea is to survive automatically to replicaset changes

fun <T> MongoCollection<T>.watchIndefinitely(watchProvider: (MongoCollection<T>) -> ChangeStreamPublisher<T>, subscribeListener: () -> Unit = {}, errorListener: (Throwable) -> Unit = {}, reopenListener: () -> Unit = {}, reopenDelayInMS: Long = 5000, listener: (ChangeStreamDocument<T>) -> Unit): Unit

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(): MongoCollection<NewTDocument>

withKMongo

Returns a MongoCollection with a KMongo codec.

fun <T> MongoCollection<T>.withKMongo(): MongoCollection<T>