MongoCollection
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 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.
Operations
The following lists the available operations using the mongosh equivalent:
updateOne with an aggregation pipeline
updateOne with
upsert: trueupdateOne with
upsert: trueand an aggregation pipelineupdateMany with an aggregation pipeline
replaceOne with
upsert: true
External resources
Properties
The full BSON configuration, used by the DSL to generate queries.
The BsonFactory used to serialize and deserialize values stored in this collection.
The algorithm used to generate new ObjectId instances for this collection.
The strategy used to convert property names to BSON document keys.
The KType instance that corresponds to the collection's document type.
Functions
Starts an aggregation pipeline on this collection.
Counts all documents in the collection.
Deletes all documents that match filter.
Deletes the first document found that matches filter.
Removes an entire collection from the database.
Tests if there exists a document that matches predicate in the collection.
Creates a client-side view containing all the documents that match filter.
Finds all documents in this collection.
Finds all documents in this collection that satisfy filter.
Finds a document in this collection that satisfies filter.
Inserts multiple documents in a single operation.