MongoCollection¶
interface MongoCollection<Document : Any> : ObjectIdGenerator
A collection stores related documents together.
Usually, all documents in a collection have the same shape (the same fields). However, heterogeneous structure can be achieved by using:
-
Kotlin collections, like
ListandSet, 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.
Properties¶
database¶
abstract val database: MongoDatabase
The MongoDatabase that contains this collection.
fullyQualifiedName¶
open val fullyQualifiedName: String
name¶
THe name of this collection.
The collection name must be unique within a single database (otherwise, the two instances refer to the same data).
type¶
@LowLevelApi
abstract val type: KType
The KType instance that corresponds to the collection's document type.
This property is used by serialization libraries to know the exact type to deserialize, especially in the presence of type parameters.
Everyday users should not need to interact with this property directly.
Functions¶
insertOne¶
abstract suspend fun insertOne(document: Document, options: InsertOneOptions<Document>.() -> Unit = {})