CollectionOperations¶
interface CollectionOperations<Document : Any> : BaseOperations
Interface grouping MongoDB operations relating to collection administration.
Inheritors¶
Properties¶
context¶
abstract val context: BsonContext
The full BSON configuration, used by the DSL to generate queries.
For more information, see BsonContext.
factory¶
abstract val factory: BsonFactory
The BsonFactory used to serialize and deserialize values.
This property stores all serialization configurations and allows creating custom BSON objects.
For more information, see BsonFactory.
objectIdGenerator¶
abstract val objectIdGenerator: ObjectIdGenerator
The algorithm used to generate new ObjectId instances.
For more information, see ObjectIdGenerator.
propertyNameStrategy¶
abstract val propertyNameStrategy: PropertyNameStrategy
The strategy used to convert property names to BSON document keys.
For more information, see PropertyNameStrategy.
Functions¶
create¶
abstract fun create(options: CreateCollectionOptions<Document>.() -> Unit = {})
Explicitly creates this collection.
MongoDB will automatically create a collection with default settings on the first write operation. This method is useful to create a collection with non-default settings.
If this method is called and the collection already exists with the same options, nothing happens. If this method is called and the collection already exists with different options, an error is thrown.
Example
Create a capped collection: a collection with a maximum size on disk:
External resources
drop¶
abstract fun drop(options: DropOptions<Document>.() -> Unit = {})
Removes an entire collection from the database.
All documents within the collection are deleted.
Indexes attached to this collection are also deleted.
Example
External resources
infos¶
abstract fun infos(options: ListCollectionsOptions.() -> Unit = {}): CollectionInfo?
Returns information about this collection.
Example
To get the options that were passed when the collection was created:
External resources