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 of documents the 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>): AggregateIterable<T>
inline fun <R : Any> aggregate(pipeline: List<Bson>): AggregateIterable<R>
@JvmName(name = "aggregateAsTWithSession")
fun aggregate(clientSession: ClientSession, pipeline: List<Bson>): AggregateIterable<T>
inline fun <R : Any> aggregate(clientSession: ClientSession, pipeline: List<Bson>): AggregateIterable<R>
fun <R : Any> aggregate(pipeline: List<Bson>, resultClass: Class<R>): AggregateIterable<R>
fun <R : Any> aggregate(clientSession: ClientSession, pipeline: List<Bson>, resultClass: Class<R>): AggregateIterable<R>

Aggregates documents according to the specified aggregation pipeline.

Link copied to clipboard
fun bulkWrite(requests: List<WriteModel<out T>>, options: BulkWriteOptions = BulkWriteOptions()): BulkWriteResult
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
fun countDocuments(filter: Bson = BsonDocument(), options: CountOptions = CountOptions()): Long

Counts the number of documents in the collection.

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
fun createIndex(keys: Bson, options: IndexOptions = IndexOptions()): String
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()): List<String>
fun createIndexes(clientSession: ClientSession, indexes: List<IndexModel>, options: CreateIndexOptions = CreateIndexOptions()): List<String>

Create multiple indexes.

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

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

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

Create an Atlas Search index for the collection.

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

Create one or more Atlas Search indexes for the collection.

Link copied to clipboard
fun deleteMany(filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteResult
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
fun deleteOne(filter: Bson, options: DeleteOptions = DeleteOptions()): DeleteResult
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> distinct(fieldName: String, filter: Bson = BsonDocument()): DistinctIterable<R>
inline fun <R> distinct(clientSession: ClientSession, fieldName: String, filter: Bson = BsonDocument()): DistinctIterable<R>
fun <R> distinct(fieldName: String, filter: Bson = BsonDocument(), resultClass: Class<R>): DistinctIterable<R>
fun <R> distinct(clientSession: ClientSession, fieldName: String, filter: Bson = BsonDocument(), resultClass: Class<R>): DistinctIterable<R>

Gets the distinct values of the specified field name.

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

Drops this collection from the Database.

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

Drops the index given its name.

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

Drops the index given the keys used to create it.

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

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

Link copied to clipboard
fun dropSearchIndex(indexName: String)

Drop an Atlas Search index given its name.

Link copied to clipboard
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()): FindIterable<T>
inline fun <R : Any> find(filter: Bson = BsonDocument()): FindIterable<R>
@JvmName(name = "findAsTWithSession")
fun find(clientSession: ClientSession, filter: Bson = BsonDocument()): FindIterable<T>
inline fun <R : Any> find(clientSession: ClientSession, filter: Bson = BsonDocument()): FindIterable<R>
fun <R : Any> find(filter: Bson = BsonDocument(), resultClass: Class<R>): FindIterable<R>
fun <R : Any> find(clientSession: ClientSession, filter: Bson = BsonDocument(), resultClass: Class<R>): FindIterable<R>

Finds all documents in the collection.

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

Atomically find a document and remove it.

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

Atomically find a document and replace it.

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

Atomically find a document and update it.

Link copied to clipboard
fun insertMany(documents: List<T>, options: InsertManyOptions = InsertManyOptions()): InsertManyResult
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
fun insertOne(document: T, options: InsertOneOptions = InsertOneOptions()): InsertOneResult
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(): ListIndexesIterable<Document>
@JvmName(name = "listIndexesAsDocumentWithSession")
fun listIndexes(clientSession: ClientSession): ListIndexesIterable<Document>
inline fun <R : Any> listIndexes(clientSession: ClientSession): ListIndexesIterable<R>
fun <R : Any> listIndexes(resultClass: Class<R>): ListIndexesIterable<R>
fun <R : Any> listIndexes(clientSession: ClientSession, resultClass: Class<R>): ListIndexesIterable<R>

Get all the indexes in this collection.

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

Get all the Atlas Search indexes in this collection.

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

Rename the collection with oldCollectionName to the newCollectionName.

Link copied to clipboard
fun replaceOne(filter: Bson, replacement: T, options: ReplaceOptions = ReplaceOptions()): UpdateResult
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
@Alpha(value = [Reason.CLIENT])
fun timeout(timeUnit: TimeUnit = TimeUnit.MILLISECONDS): Long?

The time limit for the full execution of an operation.

Link copied to clipboard
fun updateMany(filter: Bson, update: List<Bson>, options: UpdateOptions = UpdateOptions()): UpdateResult
fun updateMany(filter: Bson, update: Bson, options: UpdateOptions = UpdateOptions()): UpdateResult
fun updateMany(clientSession: ClientSession, filter: Bson, update: List<Bson>, options: UpdateOptions = UpdateOptions()): UpdateResult
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
fun updateOne(filter: Bson, update: List<Bson>, options: UpdateOptions = UpdateOptions()): UpdateResult
fun updateOne(filter: Bson, update: Bson, options: UpdateOptions = UpdateOptions()): UpdateResult
fun updateOne(clientSession: ClientSession, filter: Bson, update: List<Bson>, options: UpdateOptions = UpdateOptions()): UpdateResult
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
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()): ChangeStreamIterable<T>
inline fun <R : Any> watch(pipeline: List<Bson> = emptyList()): ChangeStreamIterable<R>
@JvmName(name = "watchAsDocumentWithSession")
fun watch(clientSession: ClientSession, pipeline: List<Bson> = emptyList()): ChangeStreamIterable<T>
inline fun <R : Any> watch(clientSession: ClientSession, pipeline: List<Bson> = emptyList()): ChangeStreamIterable<R>
fun <R : Any> watch(pipeline: List<Bson> = emptyList(), resultClass: Class<R>): ChangeStreamIterable<R>
fun <R : Any> watch(clientSession: ClientSession, pipeline: List<Bson> = emptyList(), resultClass: Class<R>): ChangeStreamIterable<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
@Alpha(value = [Reason.CLIENT])
fun withTimeout(timeout: Long, timeUnit: TimeUnit = TimeUnit.MILLISECONDS): MongoCollection<T>

Create a new MongoCollection instance with the set time limit for the full execution of an operation.

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.