MongoCollection

class MongoCollection<T : Any>(wrapped: MongoCollection<T>)

The MongoCollection representation.

Note: Additions to this interface will not be considered to break binary compatibility.

Parameters

T

The type that this collection will encode documents from and decode documents to.

Constructors

Link copied to clipboard
constructor(wrapped: MongoCollection<T>)

Functions

Link copied to clipboard
@JvmName(name = "aggregateAsT")
fun aggregate(pipeline: List<Bson>): AggregateFlow<T>
inline fun <R : Any> aggregate(pipeline: List<Bson>): AggregateFlow<R>
@JvmName(name = "aggregateAsTWithSession")
fun aggregate(clientSession: ClientSession, pipeline: List<Bson>): AggregateFlow<T>
inline fun <R : Any> aggregate(clientSession: ClientSession, pipeline: List<Bson>): AggregateFlow<R>
fun <R : Any> aggregate(pipeline: List<Bson>, resultClass: Class<R>): AggregateFlow<R>
fun <R : Any> aggregate(clientSession: ClientSession, pipeline: List<Bson>, resultClass: Class<R>): AggregateFlow<R>

Aggregates documents according to the specified aggregation pipeline.

Link copied to clipboard
suspend fun bulkWrite(requests: List<WriteModel<out T>>, options: BulkWriteOptions = BulkWriteOptions()): BulkWriteResult
suspend fun bulkWrite(clientSession: ClientSession, requests: List<WriteModel<out T>>, options: BulkWriteOptions = BulkWriteOptions()): BulkWriteResult

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

Link copied to clipboard
suspend fun countDocuments(filter: Bson = BsonDocument(), options: CountOptions = CountOptions()): Long

Counts the number of documents in the collection.

suspend fun countDocuments(clientSession: ClientSession, filter: Bson = BsonDocument(), options: CountOptions = CountOptions()): Long

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

Link copied to clipboard
suspend fun createIndex(keys: Bson, options: IndexOptions = IndexOptions()): String
suspend fun createIndex(clientSession: ClientSession, keys: Bson, options: IndexOptions = IndexOptions()): String

Create an index with the given keys and options.

Link copied to clipboard
fun createIndexes(indexes: List<IndexModel>, options: CreateIndexOptions = CreateIndexOptions()): Flow<String>
fun createIndexes(clientSession: ClientSession, indexes: List<IndexModel>, options: CreateIndexOptions = CreateIndexOptions()): Flow<String>

Create multiple indexes.

Link copied to clipboard
suspend fun createSearchIndex(definition: Bson): String

Create an Atlas Search index with default name for the collection.

suspend fun createSearchIndex(indexName: String, definition: Bson): String

Create an Atlas Search index for the collection.

Link copied to clipboard
fun createSearchIndexes(searchIndexModels: List<SearchIndexModel>): Flow<String>

Create one or more Atlas Search indexes for the collection.

Link copied to clipboard
suspend fun deleteMany(filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteResult
suspend fun deleteMany(clientSession: ClientSession, filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteResult

Removes all documents from the collection that match the given query filter.

Link copied to clipboard
suspend fun deleteOne(filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteResult
suspend fun deleteOne(clientSession: ClientSession, filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteResult

Removes at most one document from the collection that matches the given filter.

Link copied to clipboard
inline fun <R : Any> distinct(fieldName: String, filter: Bson = BsonDocument()): DistinctFlow<R>
inline fun <R : Any> distinct(clientSession: ClientSession, fieldName: String, filter: Bson = BsonDocument()): DistinctFlow<R>
fun <R : Any> distinct(fieldName: String, filter: Bson = BsonDocument(), resultClass: Class<R>): DistinctFlow<R>
fun <R : Any> distinct(clientSession: ClientSession, fieldName: String, filter: Bson = BsonDocument(), resultClass: Class<R>): DistinctFlow<R>

Gets the distinct values of the specified field name.

Link copied to clipboard
suspend fun drop(options: DropCollectionOptions = DropCollectionOptions())
suspend fun drop(clientSession: ClientSession, options: DropCollectionOptions = DropCollectionOptions())

Drops this collection from the Database.

Link copied to clipboard
suspend fun dropIndex(indexName: String, options: DropIndexOptions = DropIndexOptions())
suspend fun dropIndex(clientSession: ClientSession, indexName: String, options: DropIndexOptions = DropIndexOptions())

Drops the index given its name.

suspend fun dropIndex(keys: Bson, options: DropIndexOptions = DropIndexOptions())
suspend fun dropIndex(clientSession: ClientSession, keys: Bson, options: DropIndexOptions = DropIndexOptions())

Drops the index given the keys used to create it.

Link copied to clipboard
suspend fun dropIndexes(options: DropIndexOptions = DropIndexOptions())
suspend fun dropIndexes(clientSession: ClientSession, options: DropIndexOptions = DropIndexOptions())

Drop all the indexes on this collection, except for the default on _id.

Link copied to clipboard
suspend fun dropSearchIndex(indexName: String)

Drop an Atlas Search index given its name.

Link copied to clipboard
suspend fun estimatedDocumentCount(options: EstimatedDocumentCountOptions = EstimatedDocumentCountOptions()): Long

Gets an estimate of the count of documents in a collection using collection metadata.

Link copied to clipboard
@JvmName(name = "findAsT")
fun find(filter: Bson = BsonDocument()): FindFlow<T>
inline fun <R : Any> find(filter: Bson = BsonDocument()): FindFlow<R>
@JvmName(name = "findAsTWithSession")
fun find(clientSession: ClientSession, filter: Bson = BsonDocument()): FindFlow<T>
inline fun <R : Any> find(clientSession: ClientSession, filter: Bson = BsonDocument()): FindFlow<R>
fun <R : Any> find(filter: Bson = BsonDocument(), resultClass: Class<R>): FindFlow<R>
fun <R : Any> find(clientSession: ClientSession, filter: Bson = BsonDocument(), resultClass: Class<R>): FindFlow<R>

Finds all documents in the collection.

Link copied to clipboard
suspend fun findOneAndDelete(filter: Bson, options: FindOneAndDeleteOptions = FindOneAndDeleteOptions()): T?
suspend fun findOneAndDelete(clientSession: ClientSession, filter: Bson, options: FindOneAndDeleteOptions = FindOneAndDeleteOptions()): T?

Atomically find a document and remove it.

Link copied to clipboard
suspend fun findOneAndReplace(filter: Bson, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): T?
suspend fun findOneAndReplace(clientSession: ClientSession, filter: Bson, replacement: T, options: FindOneAndReplaceOptions = FindOneAndReplaceOptions()): T?

Atomically find a document and replace it.

Link copied to clipboard
suspend fun findOneAndUpdate(filter: Bson, update: List<Bson>, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?
suspend fun findOneAndUpdate(filter: Bson, update: Bson, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?
suspend fun findOneAndUpdate(clientSession: ClientSession, filter: Bson, update: List<Bson>, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?
suspend fun findOneAndUpdate(clientSession: ClientSession, filter: Bson, update: Bson, options: FindOneAndUpdateOptions = FindOneAndUpdateOptions()): T?

Atomically find a document and update it.

Link copied to clipboard
suspend fun insertMany(documents: List<T>, options: InsertManyOptions = InsertManyOptions()): InsertManyResult
suspend fun insertMany(clientSession: ClientSession, documents: List<T>, options: InsertManyOptions = InsertManyOptions()): InsertManyResult

Inserts one or more documents. A call to this method is equivalent to a call to the bulkWrite method

Link copied to clipboard
suspend fun insertOne(document: T, options: InsertOneOptions = InsertOneOptions()): InsertOneResult
suspend fun insertOne(clientSession: ClientSession, document: T, options: InsertOneOptions = InsertOneOptions()): InsertOneResult

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

Link copied to clipboard
@JvmName(name = "listIndexesAsDocument")
fun listIndexes(): ListIndexesFlow<Document>
inline fun <R : Any> listIndexes(): ListIndexesFlow<R>
@JvmName(name = "listIndexesAsDocumentWithSession")
fun listIndexes(clientSession: ClientSession): ListIndexesFlow<Document>
inline fun <R : Any> listIndexes(clientSession: ClientSession): ListIndexesFlow<R>
fun <R : Any> listIndexes(resultClass: Class<R>): ListIndexesFlow<R>
fun <R : Any> listIndexes(clientSession: ClientSession, resultClass: Class<R>): ListIndexesFlow<R>

Get all the indexes in this collection.

Link copied to clipboard
@JvmName(name = "listSearchIndexesAsDocument")
fun listSearchIndexes(): ListSearchIndexesFlow<Document>

Get all the Atlas Search indexes in this collection.

Link copied to clipboard
@JvmName(name = "mapReduceAsT")
fun mapReduce(mapFunction: String, reduceFunction: String): MapReduceFlow<T>
inline fun <R : Any> mapReduce(mapFunction: String, reduceFunction: String): MapReduceFlow<R>
@JvmName(name = "mapReduceAsTWithSession")
fun mapReduce(clientSession: ClientSession, mapFunction: String, reduceFunction: String): MapReduceFlow<T>
inline fun <R : Any> mapReduce(clientSession: ClientSession, mapFunction: String, reduceFunction: String): MapReduceFlow<R>
fun <R : Any> mapReduce(mapFunction: String, reduceFunction: String, resultClass: Class<R>): MapReduceFlow<R>
fun <R : Any> mapReduce(clientSession: ClientSession, mapFunction: String, reduceFunction: String, resultClass: Class<R>): MapReduceFlow<R>

Aggregates documents according to the specified map-reduce function.

Link copied to clipboard
suspend fun renameCollection(newCollectionNamespace: MongoNamespace, options: RenameCollectionOptions = RenameCollectionOptions())
suspend fun renameCollection(clientSession: ClientSession, newCollectionNamespace: MongoNamespace, options: RenameCollectionOptions = RenameCollectionOptions())

Rename the collection with oldCollectionName to the newCollectionName.

Link copied to clipboard
suspend fun replaceOne(filter: Bson, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult
suspend fun replaceOne(clientSession: ClientSession, filter: Bson, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult

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

Link copied to clipboard
suspend fun updateMany(filter: Bson, update: List<Bson>, options: UpdateOptions = UpdateOptions()): UpdateResult
suspend fun updateMany(filter: Bson, update: Bson, options: UpdateOptions = UpdateOptions()): UpdateResult
suspend fun updateMany(clientSession: ClientSession, filter: Bson, update: List<Bson>, options: UpdateOptions = UpdateOptions()): UpdateResult
suspend fun updateMany(clientSession: ClientSession, filter: Bson, update: Bson, options: UpdateOptions = UpdateOptions()): UpdateResult

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

Link copied to clipboard
suspend fun updateOne(filter: Bson, update: List<Bson>, options: UpdateOptions = UpdateOptions()): UpdateResult
suspend fun updateOne(filter: Bson, update: Bson, options: UpdateOptions = UpdateOptions()): UpdateResult
suspend fun updateOne(clientSession: ClientSession, filter: Bson, update: List<Bson>, options: UpdateOptions = UpdateOptions()): UpdateResult
suspend fun updateOne(clientSession: ClientSession, filter: Bson, update: Bson, options: UpdateOptions = UpdateOptions()): UpdateResult

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

Link copied to clipboard
suspend fun updateSearchIndex(indexName: String, definition: Bson)

Update an Atlas Search index in the collection.

Link copied to clipboard
@JvmName(name = "watchAsDocument")
fun watch(pipeline: List<Bson> = emptyList()): ChangeStreamFlow<T>
inline fun <R : Any> watch(pipeline: List<Bson> = emptyList()): ChangeStreamFlow<R>
@JvmName(name = "watchAsDocumentWithSession")
fun watch(clientSession: ClientSession, pipeline: List<Bson> = emptyList()): ChangeStreamFlow<T>
inline fun <R : Any> watch(clientSession: ClientSession, pipeline: List<Bson> = emptyList()): ChangeStreamFlow<R>
fun <R : Any> watch(pipeline: List<Bson> = emptyList(), resultClass: Class<R>): ChangeStreamFlow<R>
fun <R : Any> watch(clientSession: ClientSession, pipeline: List<Bson> = emptyList(), resultClass: Class<R>): ChangeStreamFlow<R>

Creates a change stream for this collection.

Link copied to clipboard
fun withCodecRegistry(newCodecRegistry: CodecRegistry): MongoCollection<T>

Create a new collection instance with a different codec registry.

Link copied to clipboard
fun <R : Any> withDocumentClass(resultClass: Class<R>): MongoCollection<R>

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

Link copied to clipboard
fun withReadConcern(newReadConcern: ReadConcern): MongoCollection<T>

Create a new collection instance with a different read concern.

Link copied to clipboard
fun withReadPreference(newReadPreference: ReadPreference): MongoCollection<T>

Create a new collection instance with a different read preference.

Link copied to clipboard
fun withWriteConcern(newWriteConcern: WriteConcern): MongoCollection<T>

Create a new collection instance with a different write concern.

Properties

Link copied to clipboard
val codecRegistry: CodecRegistry

The codec registry for the collection.

Link copied to clipboard

The class of documents stored in this collection.

Link copied to clipboard
val namespace: MongoNamespace

The namespace of this collection.

Link copied to clipboard
val readConcern: ReadConcern

The read concern for the collection.

Link copied to clipboard
val readPreference: ReadPreference

the read preference for the collection.

Link copied to clipboard
val writeConcern: WriteConcern

The write concern for the collection.