MongoDatabase

@ThreadSafe
interface MongoDatabase

The MongoDatabase interface.

Note: Additions to this interface will not be considered to break binary compatibility.

Since

3.0

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
abstract fun aggregate(pipeline: List<Bson>): AggregateFlow<Document>
abstract fun aggregate(clientSession: ClientSession, pipeline: List<Bson>): AggregateFlow<Document>
abstract fun <TResult : Any> aggregate(pipeline: List<Bson>, resultClass: KClass<out TResult>): AggregateFlow<TResult>
abstract fun <TResult : Any> aggregate(    clientSession: ClientSession,     pipeline: List<Bson>,     resultClass: KClass<out TResult>): AggregateFlow<TResult>

Runs an aggregation framework pipeline on the database for pipeline stages that do not require an underlying collection, such as $currentOp and $listLocalSessions.

Link copied to clipboard
abstract suspend fun createCollection(collectionName: String)
abstract suspend fun createCollection(clientSession: ClientSession, collectionName: String)

Create a new collection with the given name.

abstract suspend fun createCollection(collectionName: String, options: CreateCollectionOptions)
abstract suspend fun createCollection(    clientSession: ClientSession,     collectionName: String,     options: CreateCollectionOptions)

Create a new collection with the selected options

Link copied to clipboard
abstract suspend fun createView(    viewName: String,     viewOn: String,     pipeline: List<Bson>)
abstract suspend fun createView(    clientSession: ClientSession,     viewName: String,     viewOn: String,     pipeline: List<Bson>)

Creates a view with the given name, backing collection/view name, and aggregation pipeline that defines the view.

abstract suspend fun createView(    viewName: String,     viewOn: String,     pipeline: List<Bson>,     createViewOptions: CreateViewOptions)
abstract suspend fun createView(    clientSession: ClientSession,     viewName: String,     viewOn: String,     pipeline: List<Bson>,     createViewOptions: CreateViewOptions)

Creates a view with the given name, backing collection/view name, aggregation pipeline, and options that defines the view.

Link copied to clipboard
abstract suspend fun drop()
abstract suspend fun drop(clientSession: ClientSession)

Drops this database.

Link copied to clipboard
abstract fun getCollection(name: String): MongoCollection<Document>

Gets a collection.

abstract fun <TDocument : Any> getCollection(name: String, documentClass: KClass<TDocument>): MongoCollection<TDocument>

Gets a collection, with a specific default document class.

Link copied to clipboard
abstract fun listCollectionNames(): Flow<String>
abstract fun listCollectionNames(clientSession: ClientSession): Flow<String>

Gets the names of all the collections in this database.

Link copied to clipboard
abstract fun listCollections(): ListCollectionsFlow<Document>
abstract fun listCollections(clientSession: ClientSession): ListCollectionsFlow<Document>
abstract fun <TResult : Any> listCollections(resultClass: KClass<out TResult>): ListCollectionsFlow<TResult>
abstract fun <TResult : Any> listCollections(clientSession: ClientSession, resultClass: KClass<out TResult>): ListCollectionsFlow<TResult>

Finds all the collections in this database.

Link copied to clipboard
abstract suspend fun runCommand(command: Bson): Document
abstract suspend fun runCommand(clientSession: ClientSession, command: Bson): Document
abstract suspend fun <TResult : Any> runCommand(command: Bson, resultClass: KClass<out TResult>): TResult
abstract suspend fun <TResult : Any> runCommand(    clientSession: ClientSession,     command: Bson,     resultClass: KClass<out TResult>): TResult

Executes the given command in the context of the current database with a read preference of ReadPreference.primary.

abstract suspend fun runCommand(command: Bson, readPreference: ReadPreference): Document
abstract suspend fun runCommand(    clientSession: ClientSession,     command: Bson,     readPreference: ReadPreference): Document
abstract suspend fun <TResult : Any> runCommand(    command: Bson,     readPreference: ReadPreference,     resultClass: KClass<out TResult>): TResult
abstract suspend fun <TResult : Any> runCommand(    clientSession: ClientSession,     command: Bson,     readPreference: ReadPreference,     resultClass: KClass<out TResult>): TResult

Executes the given command in the context of the current database with the given read preference.

Link copied to clipboard
abstract fun watch(): ChangeStreamFlow<Document>
abstract fun watch(clientSession: ClientSession): ChangeStreamFlow<Document>
abstract fun watch(pipeline: List<Bson>): ChangeStreamFlow<Document>
abstract fun <TResult : Any> watch(resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>
abstract fun watch(clientSession: ClientSession, pipeline: List<Bson>): ChangeStreamFlow<Document>
abstract fun <TResult : Any> watch(clientSession: ClientSession, resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>
abstract fun <TResult : Any> watch(pipeline: List<Bson>, resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>
abstract fun <TResult : Any> watch(    clientSession: ClientSession,     pipeline: List<Bson>,     resultClass: KClass<out TResult>): ChangeStreamFlow<TResult>

Creates a change stream for this database.

Link copied to clipboard
abstract fun withCodecRegistry(codecRegistry: CodecRegistry): MongoDatabase

Create a new MongoDatabase instance with a different codec registry.

Link copied to clipboard
abstract fun withReadConcern(readConcern: ReadConcern): MongoDatabase

Create a new MongoDatabase instance with a different read concern.

Link copied to clipboard
abstract fun withReadPreference(readPreference: ReadPreference): MongoDatabase

Create a new MongoDatabase instance with a different read preference.

Link copied to clipboard
abstract fun withWriteConcern(writeConcern: WriteConcern): MongoDatabase

Create a new MongoDatabase instance with a different write concern.

Properties

Link copied to clipboard
abstract val codecRegistry: CodecRegistry

Get the codec registry for the MongoDatabase.

Link copied to clipboard
abstract val name: String

Gets the name of the database.

Link copied to clipboard
abstract val readConcern: ReadConcern

Get the read concern for the MongoDatabase.

Link copied to clipboard
abstract val readPreference: ReadPreference

Get the read preference for the MongoDatabase.

Link copied to clipboard
abstract val writeConcern: WriteConcern

Get the write concern for the MongoDatabase.

Extensions

Link copied to clipboard
inline fun <TDocument : Any> MongoDatabase.getCollectionOf(name: String): MongoCollection<TDocument>

Gets a collection, with a specific default document class.