diff --git a/build.gradle.kts b/build.gradle.kts index 7bef3df6..09b21b18 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -24,6 +24,7 @@ dependencies { dokkatoo(projects.annotations) dokkatoo(projects.bson) dokkatoo(projects.dsl) + dokkatoo(projects.driverSync) } // region Check the users of the project didn't forget to rename the group diff --git a/driver-sync/README.jvm.md b/driver-sync/README.jvm.md new file mode 100644 index 00000000..148357bf --- /dev/null +++ b/driver-sync/README.jvm.md @@ -0,0 +1,30 @@ +# Module MongoDB driver for Kotlin (synchronous) + +Blocking/synchronous driver for MongoDB, using a rich Kotlin DSL. + + + + + +## Configuration + +Start by declaring a dependency on this module (see the common page for help). + +This driver is built on the top of the [official Kotlin driver](https://www.mongodb.com/docs/languages/kotlin/kotlin-sync-driver/current/). You can use the official tutorials to get started and learn how to connect to the database. + +The most basic option is to connect to your local MongoDB instance running on `localhost:27017`, use: +```kotlin +class User( + val _id: ObjectId, + val name: String, +) + +val client = MongoClient.create() +val database = client.getDatabase("my_project") +val collection = database.getCollection("users").asKtMongo() +``` + +Note the call to [`asKtMongo()`][opensavvy.ktmongo.sync.asKtMongo] which is the only difference from the official usage. +From then on, all methods from this driver are available on the `collection` variable: see [MongoCollection][opensavvy.ktmongo.sync.MongoCollection]. + +This means you are able to use KtMongo DSLs within your existing repositories: simply convert into a KtMongo equivalent where you need KtMongo functionality. diff --git a/driver-sync/README.md b/driver-sync/README.md new file mode 100644 index 00000000..da32a0a6 --- /dev/null +++ b/driver-sync/README.md @@ -0,0 +1,73 @@ +# Module MongoDB driver for Kotlin (synchronous) + +Blocking/synchronous driver for MongoDB, using a rich Kotlin DSL. + + + + + +## Configuration + +Add a dependency on `dev.opensavvy.ktmongo:driver-sync`. + +For example, in a Kotlin Multiplatform project: +```kotlin +plugins { + kotlin("multiplatform") +} + +kotlin { + jvm() + // … + + sourceSets.commonMain.dependencies { + implementation("dev.opensavvy.ktmongo:driver-sync:VERSION-HERE") + } +} +``` + +In a Kotlin JVM project: +```kotlin +plugins { + kotlin("jvm") +} + +dependencies { + implementation("dev.opensavvy.ktmongo:driver-sync:VERSION-HERE") +} +``` + +## Basic usage + +Once you have obtained an instance of [MongoCollection][opensavvy.ktmongo.sync.MongoCollection] (see platform-specific instructions on how to do this), you can use it to access the database: + +```kotlin +class User( + val _id: ObjectId, + val name: String, + val age: Int, +) + +collection.findOne { + User::age gte 18 +} + +collection.update( + filter = { + User::_id eq ObjectId("507f1f77bcf86cd799439011") + }, + update = { + User::name set "Bob" + } +) +``` + +[Learn more about the available operations][opensavvy.ktmongo.sync.MongoCollection]. + +# Package opensavvy.ktmongo.sync + +Declaration and implementation of collections and iterables. + +# Package opensavvy.ktmongo.sync.operations + +Declaration of the different types of operations. diff --git a/driver-sync/build.gradle.kts b/driver-sync/build.gradle.kts index f0e1ebc8..1220e58f 100644 --- a/driver-sync/build.gradle.kts +++ b/driver-sync/build.gradle.kts @@ -40,7 +40,7 @@ kotlin { } library { - name.set("MongoDB synchronous driver for Kotlin") + name.set("MongoDB driver for Kotlin (synchronous)") description.set("Kotlin-first MongoDB driver") homeUrl.set("https://gitlab.com/opensavvy/ktmongo") diff --git a/driver-sync/src/commonMain/kotlin/MongoCollection.kt b/driver-sync/src/commonMain/kotlin/MongoCollection.kt index 1ae8801b..b77b90ce 100644 --- a/driver-sync/src/commonMain/kotlin/MongoCollection.kt +++ b/driver-sync/src/commonMain/kotlin/MongoCollection.kt @@ -25,8 +25,8 @@ import opensavvy.ktmongo.sync.operations.FindOperations * * ### Operations * - * - [find] - * - [findOne] + * - [find][FindOperations.find] + * - [findOne][FindOperations.findOne] * * ### External resources *