CoroutineMongoCollection

A collection stores related documents together.

The Coroutine client provides a coroutine-aware API which internally uses the official Kotlin driver.

Usually, all documents in a collection have the same shape (the same fields). However, heterogeneous structure can be achieved by using:

  • Kotlin collections, like List and Set, the embed an arbitrary number of items.

  • Polymorphism, for example with sealed class, to have different fields based on a discriminator.

To avoid name collisions, collections are grouped into databases.

To obtain a collection, see MongoDatabase.collection.

Size limit

A MongoDB document cannot exceed 16 MiB.

You can measure the size of a document with opensavvy.ktmongo.bson.BsonDocument.toByteArray followed by ByteArray.size.

The maximum nesting is 100 levels. Each document or array adds a level.

External resources

See also

Convert an existing instance from the official Kotlin driver.

Types

Link copied to clipboard

Properties

Link copied to clipboard
Link copied to clipboard
abstract override val factory: BsonFactory
Link copied to clipboard
Link copied to clipboard
abstract val name: String
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
abstract val type: KType

Functions

Link copied to clipboard
Link copied to clipboard
abstract fun asOfficial(): MongoCollection<Document>

Obtains the underlying MongoDB collection from the official Kotlin driver.

Link copied to clipboard
abstract suspend fun bulkWrite(options: BulkWriteOptions<Document>.() -> Unit, filter: FilterQuery<Document>.() -> Unit, operations: BulkWrite<Document>.() -> Unit)
Link copied to clipboard
abstract suspend fun count(): Long
abstract suspend fun count(options: CountOptions<Document>.() -> Unit, predicate: FilterQuery<Document>.() -> Unit): Long
Link copied to clipboard
abstract suspend fun countEstimated(): Long
Link copied to clipboard
abstract suspend fun deleteMany(options: DeleteManyOptions<Document>.() -> Unit, filter: FilterQuery<Document>.() -> Unit)
Link copied to clipboard
abstract suspend fun deleteOne(options: DeleteOneOptions<Document>.() -> Unit, filter: FilterQuery<Document>.() -> Unit)
Link copied to clipboard
abstract suspend fun drop(options: DropOptions<Document>.() -> Unit)
Link copied to clipboard
open suspend fun exists(options: CountOptions<Document>.() -> Unit, predicate: FilterQuery<Document>.() -> Unit): Boolean
Link copied to clipboard
abstract override fun filter(filter: FilterQuery<Document>.() -> Unit): CoroutineMongoCollection<Document>
Link copied to clipboard
abstract fun find(): MongoIterable<Document>
abstract fun find(options: FindOptions<Document>.() -> Unit, filter: FilterQuery<Document>.() -> Unit): MongoIterable<Document>
Link copied to clipboard
open suspend fun findOne(options: FindOptions<Document>.() -> Unit, filter: FilterQuery<Document>.() -> Unit): Document?
Link copied to clipboard
abstract suspend fun findOneAndUpdate(options: UpdateOptions<Document>.() -> Unit, filter: FilterQuery<Document>.() -> Unit, update: UpdateQuery<Document>.() -> Unit): Document?
Link copied to clipboard
abstract suspend fun insertMany(documents: Iterable<Document>, options: InsertManyOptions<Document>.() -> Unit)
open suspend fun insertMany(vararg documents: Document, options: InsertManyOptions<Document>.() -> Unit)
Link copied to clipboard
abstract suspend fun insertOne(document: Document, options: InsertOneOptions<Document>.() -> Unit)
Link copied to clipboard
open override fun newId(): ObjectId
Link copied to clipboard
abstract suspend fun replaceOne(options: ReplaceOptions<Document>.() -> Unit, filter: FilterQuery<Document>.() -> Unit, document: Document)
Link copied to clipboard
abstract suspend fun repsertOne(options: ReplaceOptions<Document>.() -> Unit, filter: FilterQuery<Document>.() -> Unit, document: Document)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard