MongoCollection

@ThreadSafe
interface MongoCollection<TDocument : Any>

The MongoCollection interface.

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

Since

3.0

Parameters

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

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract fun aggregate(pipeline: List<Bson>): AggregateFlow<TDocument>
abstract fun aggregate(clientSession: ClientSession, pipeline: List<Bson>): AggregateFlow<TDocument>
abstract fun <TResult : Any> aggregate(pipeline: List<Bson>, resultClass: KClass<out TResult>): AggregateFlow<TResult>
abstract fun <TResult : Any> aggregate(    clientSession: ClientSession,     pipeline: List<Bson>,     resultClass: KClass<out TResult>): AggregateFlow<TResult>

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.

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

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

Link copied to clipboard
abstract suspend fun countDocuments(): Long
abstract suspend fun countDocuments(clientSession: ClientSession): Long

Counts the number of documents in the collection.

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

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

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

Creates an index.

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

Create multiple indexes.

Link copied to clipboard
abstract suspend fun deleteMany(filter: Bson): DeleteResult
abstract suspend fun deleteMany(clientSession: ClientSession, filter: Bson): DeleteResult
abstract suspend fun deleteMany(filter: Bson, options: DeleteOptions): DeleteResult
abstract suspend fun deleteMany(    clientSession: ClientSession,     filter: Bson,     options: 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
abstract suspend fun deleteOne(filter: Bson): DeleteResult
abstract suspend fun deleteOne(clientSession: ClientSession, filter: Bson): DeleteResult
abstract suspend fun deleteOne(filter: Bson, options: DeleteOptions): DeleteResult
abstract suspend fun deleteOne(    clientSession: ClientSession,     filter: Bson,     options: 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
abstract fun <TResult : Any> distinct(fieldName: String, resultClass: KClass<out TResult>): DistinctFlow<TResult>
abstract fun <TResult : Any> distinct(    clientSession: ClientSession,     fieldName: String,     resultClass: KClass<out TResult>): DistinctFlow<TResult>
abstract fun <TResult : Any> distinct(    fieldName: String,     filter: Bson,     resultClass: KClass<out TResult>): DistinctFlow<TResult>
abstract fun <TResult : Any> distinct(    clientSession: ClientSession,     fieldName: String,     filter: Bson,     resultClass: KClass<out TResult>): DistinctFlow<TResult>

Gets the distinct values of the specified field name.

Link copied to clipboard
abstract suspend fun drop()
abstract suspend fun drop(clientSession: ClientSession)

Drops this collection from the Database.

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

Drops the index given its name.

abstract suspend fun dropIndex(keys: Bson)
abstract suspend fun dropIndex(clientSession: ClientSession, keys: Bson)
abstract suspend fun dropIndex(keys: Bson, dropIndexOptions: DropIndexOptions)
abstract suspend fun dropIndex(    clientSession: ClientSession,     keys: Bson,     dropIndexOptions: DropIndexOptions)

Drops the index given the keys used to create it.

Link copied to clipboard
abstract suspend fun dropIndexes()
abstract suspend fun dropIndexes(dropIndexOptions: DropIndexOptions)
abstract suspend fun dropIndexes(clientSession: ClientSession)
abstract suspend fun dropIndexes(clientSession: ClientSession, dropIndexOptions: DropIndexOptions)

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

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

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

Link copied to clipboard
abstract fun find(): FindFlow<TDocument>
abstract fun find(clientSession: ClientSession): FindFlow<TDocument>
abstract fun <TResult : Any> find(resultClass: KClass<out TResult>): FindFlow<TResult>
abstract fun find(filter: Bson): FindFlow<TDocument>
abstract fun <TResult : Any> find(clientSession: ClientSession, resultClass: KClass<out TResult>): FindFlow<TResult>
abstract fun find(clientSession: ClientSession, filter: Bson): FindFlow<TDocument>
abstract fun <TResult : Any> find(filter: Bson, resultClass: KClass<out TResult>): FindFlow<TResult>
abstract fun <TResult : Any> find(    clientSession: ClientSession,     filter: Bson,     resultClass: KClass<out TResult>): FindFlow<TResult>

Finds all documents in the collection.

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

Atomically find a document and remove it.

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

Atomically find a document and replace it.

Link copied to clipboard
abstract suspend fun findOneAndUpdate(filter: Bson, update: Bson): TDocument?
abstract suspend fun findOneAndUpdate(    clientSession: ClientSession,     filter: Bson,     update: Bson): TDocument?
abstract suspend fun findOneAndUpdate(    filter: Bson,     update: Bson,     options: FindOneAndUpdateOptions): TDocument?
abstract suspend fun findOneAndUpdate(    clientSession: ClientSession,     filter: Bson,     update: Bson,     options: FindOneAndUpdateOptions): TDocument?

Atomically find a document and update it.

Link copied to clipboard
abstract suspend fun insertMany(documents: List<TDocument>): InsertManyResult
abstract suspend fun insertMany(clientSession: ClientSession, documents: List<TDocument>): InsertManyResult
abstract suspend fun insertMany(documents: List<TDocument>, options: InsertManyOptions): InsertManyResult
abstract suspend fun insertMany(    clientSession: ClientSession,     documents: List<TDocument>,     options: 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
abstract suspend fun insertOne(document: TDocument): InsertOneResult
abstract suspend fun insertOne(document: TDocument, options: InsertOneOptions): InsertOneResult
abstract suspend fun insertOne(clientSession: ClientSession, document: TDocument): InsertOneResult
abstract suspend fun insertOne(    clientSession: ClientSession,     document: TDocument,     options: InsertOneOptions): InsertOneResult

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

Link copied to clipboard
abstract fun listIndexes(): ListIndexesFlow<Document>
abstract fun listIndexes(clientSession: ClientSession): ListIndexesFlow<Document>
abstract fun <TResult : Any> listIndexes(resultClass: KClass<out TResult>): ListIndexesFlow<TResult>
abstract fun <TResult : Any> listIndexes(clientSession: ClientSession, resultClass: KClass<out TResult>): ListIndexesFlow<TResult>

Get all the indexes in this collection.

Link copied to clipboard
abstract fun mapReduce(mapFunction: String, reduceFunction: String): MapReduceFlow<TDocument>
abstract fun mapReduce(    clientSession: ClientSession,     mapFunction: String,     reduceFunction: String): MapReduceFlow<TDocument>
abstract fun <TResult : Any> mapReduce(    mapFunction: String,     reduceFunction: String,     resultClass: KClass<out TResult>): MapReduceFlow<TResult>
abstract fun <TResult : Any> mapReduce(    clientSession: ClientSession,     mapFunction: String,     reduceFunction: String,     resultClass: KClass<out TResult>): MapReduceFlow<TResult>

Aggregates documents according to the specified map-reduce function.

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

Rename the collection with oldCollectionName to the newCollectionName.

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

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

Link copied to clipboard
abstract suspend fun updateMany(filter: Bson, update: Bson): UpdateResult
abstract suspend fun updateMany(    clientSession: ClientSession,     filter: Bson,     update: Bson): UpdateResult
abstract suspend fun updateMany(    filter: Bson,     update: Bson,     options: UpdateOptions): UpdateResult
abstract suspend fun updateMany(    clientSession: ClientSession,     filter: Bson,     update: Bson,     options: UpdateOptions): UpdateResult

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

Link copied to clipboard
abstract suspend fun updateOne(filter: Bson, update: Bson): UpdateResult
abstract suspend fun updateOne(    clientSession: ClientSession,     filter: Bson,     update: Bson): UpdateResult
abstract suspend fun updateOne(    filter: Bson,     update: Bson,     options: UpdateOptions): UpdateResult
abstract suspend fun updateOne(    clientSession: ClientSession,     filter: Bson,     update: Bson,     options: UpdateOptions): UpdateResult

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

Link copied to clipboard
abstract fun watch(): ChangeStreamFlow<Document>
abstract fun watch(clientSession: ClientSession): ChangeStreamFlow<Document>
abstract fun watch(pipeline: List<Bson>): ChangeStreamFlow<Document>
abstract fun <TResult : Any> watch(resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>
abstract fun watch(clientSession: ClientSession, pipeline: List<Bson>): ChangeStreamFlow<Document>
abstract fun <TResult : Any> watch(clientSession: ClientSession, resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>
abstract fun <TResult : Any> watch(pipeline: List<Bson>, resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>
abstract fun <TResult : Any> watch(    clientSession: ClientSession,     pipeline: List<Bson>,     resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>

Creates a change stream for this collection.

Link copied to clipboard
abstract fun withCodecRegistry(codecRegistry: CodecRegistry): MongoCollection<TDocument>

Create a new MongoCollection instance with a different codec registry.

Link copied to clipboard
abstract fun <NewTDocument : Any> withDocumentClass(newDocumentClass: KClass<NewTDocument>): MongoCollection<NewTDocument>

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

Link copied to clipboard
abstract fun withReadConcern(readConcern: ReadConcern): MongoCollection<TDocument>

Create a new MongoCollection instance with a different read concern.

Link copied to clipboard
abstract fun withReadPreference(readPreference: ReadPreference): MongoCollection<TDocument>

Create a new MongoCollection instance with a different read preference.

Link copied to clipboard
abstract fun withWriteConcern(writeConcern: WriteConcern): MongoCollection<TDocument>

Create a new MongoCollection instance with a different write concern.

Properties

Link copied to clipboard
abstract val codecRegistry: CodecRegistry

Get the codec registry for the MongoCollection.

Link copied to clipboard
abstract val documentClass: KClass<TDocument>

Get the class of documents stored in this collection.

Link copied to clipboard
abstract val namespace: MongoNamespace

Gets the namespace of this collection.

Link copied to clipboard
abstract val readConcern: ReadConcern

Get the read concern for the MongoCollection.

Link copied to clipboard
abstract val readPreference: ReadPreference

Get the read preference for the MongoCollection.

Link copied to clipboard
abstract val writeConcern: WriteConcern

Get the write concern for the MongoCollection.