KongoService

interface KongoService<T : Any>(source)

A service for abstracting MongoDB internals.

Example:

data class Foo(
@SerialName("_id") val id: DocumentId,
val bar: String
)

class FooService : KongoService<Foo> {
override val info by meta(name = "test")
override val database by inject() // provide instance however you want

suspend fun getFoo(bar: String): Result<Foo> = operation {
find { Foo::bar equals bar }.first()
}
}

Types

Link copied to clipboard
data class Info<T : Any>(val name: String, val type: Class<T>, val options: CreateCollectionOptions)

Information describing your Kongo service. Use the meta delegate for less verbosity.

Properties

Link copied to clipboard
open val collection: MongoCollection<T>

The MongoDB collection associated with this service. By default, gets the collection from the database property.

Link copied to clipboard
abstract val database: MongoDatabase

The database used with this service.

Link copied to clipboard
abstract val info: KongoService.Info<T>

Metadata for the service. See meta.

Functions

Link copied to clipboard
inline fun <T : Any> KongoService<T>.meta(name: String, options: CreateCollectionOptions = CreateCollectionOptions()): ReadOnlyProperty<Any?, KongoService.Info<T>>

Automatically configures KongoService.Info for your service.

Link copied to clipboard
open suspend fun <R> operation(fn: suspend MongoCollection<T>.() -> R): Result<R>

Runs an operation on this collection.