
Enhances MongoDB driver usability with utilities offering DSL patterns for operations, automatic SerialName fetching, ergonomic service interfaces, and DocumentId for data model sharing without MongoDB driver dependency.
Transform the MongoDB Kotlin driver into actual Kotlin.
Still experimental, expect breaking changes until 1.0.
All modules are multiplatform.
If you wish to use them in a JVM-only project, append
-jvmto the coordinates.
build.gradle.kts
dependencies {
// to use in a JVM-only project, use `services-jvm`
// includes both `model-core` and `model-bson`
implementation("dev.stashy.kongo:services:???")
// or, if you only care about the ObjectId replacement...:
// core data structures, multiplatform
implementation("dev.stashy.kongo:model-core:???")
// BSON serializer for DocumentId - depends on `bson-kotlinx`
implementation("dev.stashy.kongo:model-bson:???")
}libs.versions.toml
[libraries]
kongo-model-core = { module = "dev.stashy.kongo:model-core", version.ref = "kongo" }
kongo-model-bson = { module = "dev.stashy.kongo:model-bson", version.ref = "kongo" }
kongo-services = { module = "dev.stashy.kongo:services", version.ref = "kongo" }@SerialName use in BSONDocumentId - an ObjectId replacement that you can use in non-server modules, without the need to import any
MongoDB libraries.Most importantly: you can use as much of this library as you need. Everything is a wrapper over the actual MongoDB Kotlin driver, allowing you to adopt the library in stages if needed.
data class Foo(@SerialName("_id") val id: DocumentId, val bar: String)
filter {
(Foo::bar equals "bar") or (Foo::bar equals "baz")
}
// the above is equivalent to:
Filters.or(
Filters.eq(Foo::bar.name, "bar"),
Filters.eq(Foo::bar.name, "baz")
)
// ...with the added benefit of automatically
// using names from the SerialName annotation.val collection: MongoCollection<Foo> = TODO()
collection.find { Foo::id equals "bar" }.first()
collection.updateOne(
options = { upsert(true) },
filter = { Foo::id equals "bar" },
update = { Foo::bar set "baz" }
)class FooService : KongoService<Foo> {
override val info by meta(name = "test")
override val database by inject() // provide the instance however you want
suspend fun getFoo(bar: String): Result<Foo> = operation {
find { Foo::bar equals bar }.first()
}
}See KongoService documentation for more information.
Transform the MongoDB Kotlin driver into actual Kotlin.
Still experimental, expect breaking changes until 1.0.
All modules are multiplatform.
If you wish to use them in a JVM-only project, append
-jvmto the coordinates.
build.gradle.kts
dependencies {
// to use in a JVM-only project, use `services-jvm`
// includes both `model-core` and `model-bson`
implementation("dev.stashy.kongo:services:???")
// or, if you only care about the ObjectId replacement...:
// core data structures, multiplatform
implementation("dev.stashy.kongo:model-core:???")
// BSON serializer for DocumentId - depends on `bson-kotlinx`
implementation("dev.stashy.kongo:model-bson:???")
}libs.versions.toml
[libraries]
kongo-model-core = { module = "dev.stashy.kongo:model-core", version.ref = "kongo" }
kongo-model-bson = { module = "dev.stashy.kongo:model-bson", version.ref = "kongo" }
kongo-services = { module = "dev.stashy.kongo:services", version.ref = "kongo" }@SerialName use in BSONDocumentId - an ObjectId replacement that you can use in non-server modules, without the need to import any
MongoDB libraries.Most importantly: you can use as much of this library as you need. Everything is a wrapper over the actual MongoDB Kotlin driver, allowing you to adopt the library in stages if needed.
data class Foo(@SerialName("_id") val id: DocumentId, val bar: String)
filter {
(Foo::bar equals "bar") or (Foo::bar equals "baz")
}
// the above is equivalent to:
Filters.or(
Filters.eq(Foo::bar.name, "bar"),
Filters.eq(Foo::bar.name, "baz")
)
// ...with the added benefit of automatically
// using names from the SerialName annotation.val collection: MongoCollection<Foo> = TODO()
collection.find { Foo::id equals "bar" }.first()
collection.updateOne(
options = { upsert(true) },
filter = { Foo::id equals "bar" },
update = { Foo::bar set "baz" }
)class FooService : KongoService<Foo> {
override val info by meta(name = "test")
override val database by inject() // provide the instance however you want
suspend fun getFoo(bar: String): Result<Foo> = operation {
find { Foo::bar equals bar }.first()
}
}See KongoService documentation for more information.