{"id":18398818,"url":"https://github.com/mongodb-developer/kotlin-driver-quick-start","last_synced_at":"2025-04-14T10:52:45.423Z","repository":{"id":173958628,"uuid":"650164705","full_name":"mongodb-developer/kotlin-driver-quick-start","owner":"mongodb-developer","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-28T12:44:36.000Z","size":117,"stargazers_count":11,"open_issues_count":1,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T00:06:33.480Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mongodb-developer.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-06-06T13:32:48.000Z","updated_at":"2025-03-17T18:30:16.000Z","dependencies_parsed_at":null,"dependency_job_id":"48e14eb1-06cb-40b8-9b87-e90a554b3dd8","html_url":"https://github.com/mongodb-developer/kotlin-driver-quick-start","commit_stats":null,"previous_names":["mongodb-developer/kotlin-driver-quick-start"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fkotlin-driver-quick-start","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fkotlin-driver-quick-start/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fkotlin-driver-quick-start/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-developer%2Fkotlin-driver-quick-start/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongodb-developer","download_url":"https://codeload.github.com/mongodb-developer/kotlin-driver-quick-start/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248868808,"owners_count":21174755,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-06T02:24:34.273Z","updated_at":"2025-04-14T10:52:45.416Z","avatar_url":"https://github.com/mongodb-developer.png","language":"Kotlin","readme":"# Getting Started With the MongoDB Kotlin Driver\n\n\u003e This is an introductory article on how to build an application in Kotlin using [MongoDB Atlas](https://www.mongodb.com/atlas/database) and\n\u003e the [MongoDB Kotlin driver](https://github.com/mongodb-developer/kotlin-driver-quick-start), the latest addition to our list of official drivers.\n\u003e Together, we'll build a CRUD application that covers the basics of how to use MongoDB as a database, while leveraging the benefits of Kotlin as a\n\u003e programming language, like data classes, coroutines, and flow.\n\n## Prerequisites\n\nThis is a getting-started article. Therefore, not much is needed as a prerequisite, but familiarity with Kotlin as a programming language will be\nhelpful.\n\nAlso, we need an [Atlas account](https://www.mongodb.com/cloud/atlas/register), which is free forever. Create an account if you haven't got one. This\nprovides MongoDB as a cloud database and much more. Later in this tutorial, we'll use this account to create a new cluster, load a dataset, and\neventually query against it.\n\nIn general, MongoDB is an open-source, cross-platform, and distributed document database that allows building apps with flexible schema. In case you\nare not familiar with it or would like a quick recap, I recommend exploring\nthe [MongoDB Jumpstart series](https://www.youtube.com/watch?v=RGfFpQF0NpE\u0026list=PL4RCxklHWZ9v2lcat4oEVGQhZg6r4IQGV) to get familiar with MongoDB and\nits various services in under 10 minutes. Or if you prefer to read, then you can follow\nour [guide](https://www.mongodb.com/docs/atlas/getting-started/).\n\nAnd last, to aid our development activities, we will be using [Jetbrains IntelliJ IDEA (Community Edition)](https://www.jetbrains.com/idea/download/),\nwhich has default support for the Kotlin language.\n\n## MongoDB Kotlin driver vs MongoDB Realm Kotlin SDK\n\nBefore we start, I would like to touch base on [Realm Kotlin SDK](https://www.mongodb.com/docs/realm/sdk/kotlin/), one of the SDKs used to create\nclient-side mobile applications using the MongoDB ecosystem. It shouldn't be confused with\nthe [MongoDB Kotlin driver](https://www.mongodb.com/docs/drivers/kotlin/coroutine/current/) for server-side programming.\nThe [MongoDB Kotlin driver](https://www.mongodb.com/docs/drivers/kotlin/coroutine/current/), a language driver, enables you to seamlessly interact\nwith [Atlas](https://www.mongodb.com/atlas/database), a cloud database, with the benefits of the Kotlin language paradigm. It's appropriate to create\nbackend apps, scripts, etc.\n\nTo make learning more meaningful and practical, we'll be building a CRUD application. Feel free to check out our\n[Github repo](https://github.com/mongodb-developer/kotlin-driver-quick-start) if you would like to follow along together. So, without further ado,\nlet's get started.\n\n## Create a project\n\nTo create the project, we can use the project wizard, which can be found under the `File` menu options. Then, select `New`, followed by `Project`.\nThis will open the `New Project` screen, as shown below, then update the project and language to Kotlin.\n\n![Project wizard](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltbce8e7adda583e3e/648793838b23a5b3d5052b69/Screenshot_2023-06-12_at_09.34.09.png)\n\nAfter the initial Gradle sync, our project is ready to run. So, let's give it a try using the run icon in the menu bar, or simply press CTRL + R on\nMac. Currently, our project won't do much apart from printing `Hello World!` and arguments supplied, but the `BUILD SUCCESSFUL` message in the run\nconsole is what we're looking for, which tells us that our project setup is complete.\n\n![build success](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt97a67a3d4a402196/64879383d40ad08ec16808a9/Screenshot_2023-06-12_at_13.42.38.png)\n\nNow, the next step is to add the Kotlin driver to our project, which allows us to interact\nwith [MongoDB Atlas](https://www.mongodb.com/atlas/database).\n\n## Adding the MongoDB Kotlin driver\n\nAdding the driver to the project is simple and straightforward. Just update the `dependencies` block with the Kotlin driver dependency in the build\nfile — i.e., `build.gradle`.\n\n```groovy\ndependencies {\n    // Kotlin coroutine dependency\n    implementation(\"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4\")\n\n    // MongoDB Kotlin driver dependency\n    implementation(\"org.mongodb:mongodb-driver-kotlin-coroutine:4.10.1\")\n}\n```\n\nAnd now, we are ready to connect with [MongoDB Atlas](https://www.mongodb.com/atlas/database) using the Kotlin driver.\n\n## Connecting to the database\n\nTo connect with the database, we first need the `Connection URI` that can be found by pressing `connect to cluster` in\nour [Atlas account](https://www.mongodb.com/cloud/atlas/register), as shown below.\n\n![image](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt1d92c6f1c6654b04/648c2ff42429af5fa2f487e4/atlas_connection_copy_string_kotlin.png)\n\nFor more details, you can also refer to our [documentation](https://www.mongodb.com/docs/guides/atlas/connection-string/).\n\nWith the connection URI available, the next step is to create a Kotlin file. `Setup.kt` is where we write the code for connecting\nto [MongoDB Atlas](https://www.mongodb.com/atlas/database).\n\n![Setup.kt file](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltdc533d1983ce2f87/6488261e8b23a52669052cee/Screenshot_2023-06-13_at_09.17.29.png)\n\nConnection with our database can be split into two steps. First, we create a MongoClient instance using `Connection URI`.\n\n```kotlin\nval connectionString = \"mongodb+srv://\u003cusername\u003e:\u003center your password\u003e@cluster0.sq3aiau.mongodb.net/?retryWrites=true\u0026w=majority\"\nval client = MongoClient.create(connectionString = connectString)\n```\n\nAnd second, use client to connect with the database, `sample_restaurants`, which is a sample dataset for\nrestaurants. A [sample dataset](https://www.mongodb.com/docs/atlas/sample-data/) is a great way to explore the platform and build a more realistic POC\nto validate your ideas. To learn how to seed your first Atlas database with sample\ndata, [visit the docs](https://www.mongodb.com/docs/atlas/sample-data/).\n\n```kotlin\nval databaseName = \"sample_restaurants\"\nval db: MongoDatabase = client.getDatabase(databaseName = databaseName)\n```\n\nHardcoding `connectionString` isn't a good approach and can lead to security risks or an inability to provide role-based access. To avoid such issues\nand follow the best practices, we will be using environment variables. Other common approaches are the use of Vault, build configuration variables,\nand CI/CD environment variables.\n\nTo add environment variables, use `Modify run configuration`, which can be found by right-clicking on the file.\n\n![add environment variable](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt8438bbb2ace0979e/64882bac83c7fb1a685f3d1b/Screenshot_2023-06-13_at_09.38.49.png)\n\nTogether with code to access the environment variable, our final code looks like this.\n\n```kotlin\nsuspend fun setupConnection(\n    databaseName: String = \"sample_restaurants\",\n    connectionEnvVariable: String = \"MONGODB_URI\"\n): MongoDatabase? {\n    val connectString = if (System.getenv(connectionEnvVariable) != null) {\n        System.getenv(connectionEnvVariable)\n    } else {\n        \"mongodb+srv://\u003cusename\u003e:\u003cpassword\u003e@cluster0.sq3aiau.mongodb.net/?retryWrites=true\u0026w=majority\"\n    }\n\n    val client = MongoClient.create(connectionString = connectString)\n    val database = client.getDatabase(databaseName = databaseName)\n\n    return try {\n        // Send a ping to confirm a successful connection\n        val command = Document(\"ping\", BsonInt64(1))\n        database.runCommand(command)\n        println(\"Pinged your deployment. You successfully connected to MongoDB!\")\n        database\n    } catch (me: MongoException) {\n        System.err.println(me)\n        null\n    }\n}\n```\n\n\u003e In the code snippet above, we still have the ability to use a hardcoded string. This is only done for demo purposes, allowing you to use a\n\u003e connection URI directly for ease and to run this via any online editor. But it is strongly recommended to avoid hardcoding a connection URI.\n\nWith the `setupConnection` function ready, let's test it and query the database for the collection count and name.\n\n```kotlin\nsuspend fun listAllCollection(database: MongoDatabase) {\n\n    val count = database.listCollectionNames().count()\n    println(\"Collection count $count\")\n\n    print(\"Collection in this database are -----------\u003e \")\n    database.listCollectionNames().collect { print(\" $it\") }\n}\n```\n\nUpon running that code, our output looks like this:\n\n![list collection output](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt5a670a8008abba48/648835185953929729a04668/Screenshot_2023-06-13_at_10.21.15.png)\n\nBy now, you may have noticed that we are using the `suspend` keyword with `listAllCollection()`. `listCollectionNames()` is an asynchronous function\nas it interacts with the database and therefore would ideally run on a different thread. And since the MongoDB Kotlin driver\nsupports [Coroutines](https://kotlinlang.org/docs/coroutines-guide.html), the\nnative [Kotlin asynchronous language paradigm](https://kotlinlang.org/docs/async-programming.html), we can benefit from it by using `suspend`\nfunctions.\n\nSimilarly, to drop collections, we use the `suspend` function.\n\n```kotlin\nsuspend fun dropCollection(database: MongoDatabase) {\n    database.getCollection\u003cObjects\u003e(collectionName = \"restaurants\").drop()\n}\n```\n\nWith this complete, we are all set to start working on our CRUD application. So to start with, we need to create a `data` class that represents\nrestaurant information that our app saves into the database.\n\n```kotlin\ndata class Restaurant(\n    @BsonId\n    val id: ObjectId,\n    val address: Address,\n    val borough: String,\n    val cuisine: String,\n    val grades: List\u003cGrade\u003e,\n    val name: String,\n    @BsonProperty(\"restaurant_id\")\n    val restaurantId: String\n)\n\ndata class Address(\n    val building: String,\n    val street: String,\n    val zipcode: String,\n    val coord: List\u003cDouble\u003e\n)\n\ndata class Grade(\n    val date: LocalDateTime,\n    val grade: String,\n    val score: Int\n)\n```\n\nIn the above code snippet, we used two annotations:\n\n1. `@BsonId`, which represents the unique identity or `_id` of a document.\n2. `@BsonProperty`, which creates an alias for keys in the document — for example, `restaurantId` represents `restaurant_id`.\n\n\u003e Note: Our `Restaurant` data class here is an exact replica of a restaurant document in the sample dataset, but a few fields can be skipped or marked\n\u003e as optional — e.g., `grades` and `address` — while maintaining the ability to perform CRUD operations. We are able to do so, as MongoDB’s document\n\u003e model allows flexible schema for our data.\n\n## Create\n\nWith all the heavy lifting done (10 lines of code for connecting), adding a new document to the database is really simple and can be done with one\nline of code using `insertOne`. So, let's create a new file called `Create.kt`, which will contain all the create operations.\n\n```kotlin\nsuspend fun addItem(database: MongoDatabase) {\n\n    val collection = database.getCollection\u003cRestaurant\u003e(collectionName = \"restaurants\")\n    val item = Restaurant(\n        id = ObjectId(),\n        address = Address(\n            building = \"Building\", street = \"street\", zipcode = \"zipcode\", coord =\n            listOf(Random.nextDouble(), Random.nextDouble())\n        ),\n        borough = \"borough\",\n        cuisine = \"cuisine\",\n        grades = listOf(\n            Grade(\n                date = LocalDateTime.now(),\n                grade = \"A\",\n                score = Random.nextInt()\n            )\n        ),\n        name = \"name\",\n        restaurantId = \"restaurantId\"\n    )\n\n    collection.insertOne(item).also {\n        println(\"Item added with id - ${it.insertedId}\")\n    }\n}\n```\n\nWhen we run it, the output on the console is:\n\n![insert one](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt1d124cbfb185d7d6/648ae0b2359ef0161360df47/Screenshot_2023-06-15_at_10.49.33.png)\n\n\u003e Again, don't forget to add an environment variable again for this file, if you had trouble while running it.\n\nIf we want to add multiple documents to the collection, we can use `insertMany`, which is recommended over running `insertOne` in a loop.\n\n```kotlin\nsuspend fun addItems(database: MongoDatabase) {\n    val collection = database.getCollection\u003cRestaurant\u003e(collectionName = \"restaurants\")\n    val newRestaurants = collection.find\u003cRestaurant\u003e().first().run {\n        listOf(\n            this.copy(\n                id = ObjectId(), name = \"Insert Many Restaurant first\", restaurantId = Random\n                    .nextInt().toString()\n            ),\n            this.copy(\n                id = ObjectId(), name = \"Insert Many Restaurant second\", restaurantId = Random\n                    .nextInt().toString()\n            )\n        )\n    }\n\n    collection.insertMany(newRestaurants).also {\n        println(\"Total items added ${it.insertedIds.size}\")\n    }\n}\n\n```\n\n![Insert many output](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt02fc3f33de844c88/648ae1ce2c4f87306c1b12ce/Screenshot_2023-06-15_at_11.02.48.png)\n\nWith these outputs on the console, we can say that the data has been added successfully.\n\nBut what if we want to see the object in the database? One way is with a read operation, which we would do shortly or\nuse [MongoDB Compass](https://www.mongodb.com/products/compass) to view the information.\n\n[MongoDB Compass](https://www.mongodb.com/products/compass) is a free, interactive GUI tool for querying, optimizing, and analyzing the MongoDB data\nfrom your system. To get started, [download](https://www.mongodb.com/try/download/shell) the tool and use the `connectionString` to connect with the\ndatabase.\n\n![MongoDB compass](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blt72fd049dd230ea55/648ae40e1fb2d38f0e495940/Screenshot_2023-06-15_at_11.12.23.png)\n\n## Read\n\nTo read the information from the database, we can use the `find` operator. Let's begin by reading any document.\n\n```kotlin\nval collection = database.getCollection\u003cRestaurant\u003e(collectionName = \"restaurants\")\ncollection.find\u003cRestaurant\u003e().limit(1).collect {\n    println(it)\n}\n```\n\nThe `find` operator returns a list of results, but since we are only interested in a single document, we can use the `limit` operator in conjunction\nto limit our result set. In this case, it would be a single document.\n\nIf we extend this further and want to read a specific document, we can add filter parameters over the top of it:\n\n```kotlin\nval queryParams = Filters\n    .and(\n        listOf(\n            eq(\"cuisine\", \"American\"),\n            eq(\"borough\", \"Queens\")\n        )\n    )\n```\n\nOr, we can use any of the operators from our [list](https://www.mongodb.com/docs/manual/reference/operator/query/). The final code looks like this.\n\n```kotlin\nsuspend fun readSpecificDocument(database: MongoDatabase) {\n    val collection = database.getCollection\u003cRestaurant\u003e(collectionName = \"restaurants\")\n    val queryParams = Filters\n        .and(\n            listOf(\n                eq(\"cuisine\", \"American\"),\n                eq(\"borough\", \"Queens\")\n            )\n        )\n\n\n    collection\n        .find\u003cRestaurant\u003e(queryParams)\n        .limit(2)\n        .collect {\n            println(it)\n        }\n\n}\n```\n\nFor the output, we see this:\n\n![read specific doc output](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/bltd837ac1a039ae43f/648ae83f0f2d9b551eed55e2/Screenshot_2023-06-15_at_11.30.20.png)\n\n\u003e Don't forget to add the environment variable again for this file, if you had trouble while running it.\n\nAnother practical use case that comes with a read operation is how to add pagination to the results. This can be done with the `limit` and `offset`\noperators.\n\n```kotlin\nsuspend fun readWithPaging(database: MongoDatabase, offset: Int, pageSize: Int) {\n    val collection = database.getCollection\u003cRestaurant\u003e(collectionName = \"restaurants\")\n    val queryParams = Filters\n        .and(\n            listOf(\n                eq(Restaurant::cuisine.name, \"American\"),\n                eq(Restaurant::borough.name, \"Queens\")\n            )\n        )\n\n    collection\n        .find\u003cRestaurant\u003e(queryParams)\n        .limit(pageSize)\n        .skip(offset)\n        .collect {\n            println(it)\n        }\n}\n```\n\nBut with this approach, often, the query response time increases with value of the `offset`. To overcome this, we can benefit by creating an `Index`,\nas shown below.\n\n```kotlin\nval collection = database.getCollection\u003cRestaurant\u003e(collectionName = \"restaurants\")\nval options = IndexOptions().apply {\n    this.name(\"restaurant_id_index\")\n    this.background(true)\n}\n\ncollection.createIndex(\n    keys = Indexes.ascending(\"restaurant_id\"),\n    options = options\n)\n```\n\n## Update\n\nNow, let's discuss how to edit/update an existing document. Again, let's quickly create a new Kotlin file, `Update.Kt`.\n\nIn general, there are two ways of updating any document:\n\n* Perform an **update** operation, which allows us to update specific fields of the matching documents without impacting the other fields.\n* Perform a **replace** operation to replace the matching document with the new document.\n\nFor this exercise, we'll use the document we created earlier with the create operation `{restaurant_id: \"restaurantId\"}` and update\nthe `restaurant_id` with a more realistic value. Let's split this into two sub-tasks for clarity.\n\nFirst, using `Filters`, we query to filter the document, similar to the read operation earlier.\n\n```kotlin\nval collection = db.getCollection\u003cRestaurant\u003e(\"restaurants\")\nval queryParam = Filters.eq(\"restaurant_id\", \"restaurantId\")\n```\n\nThen, we can set the `restaurant_id` with a random integer value using `Updates`.\n\n```kotlin\nval updateParams = Updates.set(\"restaurant_id\", Random.nextInt().toString())\n```\n\nAnd finally, we use `updateOne` to update the document in an atomic operation.\n\n```kotlin\ncollection.updateOne(filter = queryParam, update = updateParams).also {\n    println(\"Total docs modified ${it.matchedCount} and fields modified ${it.modifiedCount}\")\n}\n```\n\nIn the above example, we were already aware of which document we wanted to update — the restaurant with an id `restauratantId` — but there could be a\nfew use cases where that might not be the situation. In such cases, we would first look up the document and then update it. `findOneAndUpdate` can be\nhandy. It allows you to combine both of these processes into an atomic operation, unlocking additional performance.\n\nAnother variation of the same could be updating multiple documents with one call. `updateMany` is useful for such use cases — for example, if we want\nto update the `cuisine` of all restaurants to your favourite type of cuisine and `borough` to Brooklyn.\n\n```kotlin\nsuspend fun updateMultipleDocuments(db: MongoDatabase) {\n    val collection = db.getCollection\u003cRestaurant\u003e(\"restaurants\")\n    val queryParam = Filters.eq(Restaurant::cuisine.name, \"Chinese\")\n    val updateParams = Updates.combine(\n        Updates.set(Restaurant::cuisine.name, \"Indian\"),\n        Updates.set(Restaurant::borough.name, \"Brooklyn\")\n    )\n\n    collection.updateMany(filter = queryParam, update = updateParams).also {\n        println(\"Total docs matched ${it.matchedCount} and modified ${it.modifiedCount}\")\n    }\n}\n```\n\nIn these examples, we used `set` and `combine` with `Updates`. But there are many more types of update operator to explore that allow us to do many\nintuitive operations, like set the currentDate or timestamp, increase or decrease the value of the field, and so on. To learn more about the different\ntypes of update operators you can perform with Kotlin and MongoDB, refer to\nour [docs](https://mongodb.github.io/mongo-java-driver/4.9/apidocs/mongodb-driver-core/com/mongodb/client/model/Updates.html).\n\n## Delete\n\nNow, let's explore one final CRUD operation: delete. We'll start by exploring how to delete a single document. To do this, we'll\nuse `findOneAndDelete` instead of `deleteOne`. As an added benefit, this also returns the deleted document as output. In our example, we delete the\nrestaurant:\n\n```kotlin\nval collection = db.getCollection\u003cRestaurant\u003e(collectionName = \"restaurants\")\nval queryParams = Filters.eq(\"restaurant_id\", \"restaurantId\")\n\ncollection.findOneAndDelete(filter = queryParams).also {\n    it?.let {\n        println(it)\n    }\n}\n```\n\n![delete output](https://images.contentstack.io/v3/assets/blt39790b633ee0d5a7/blta4bb9c39c2356306/6489bf30352ac64eebda33c6/Screenshot_2023-06-14_at_14.21.37.png)\n\nTo delete multiple documents, we can use `deleteMany`. We can, for example, use this to delete all the data we created earlier with our create\noperation.\n\n```kotlin\nsuspend fun deleteRestaurants(db: MongoDatabase) {\n    val collection = db.getCollection\u003cRestaurant\u003e(collectionName = \"restaurants\")\n\n    val queryParams = Filters.or(\n        listOf(\n            Filters.regex(Restaurant::name.name, Pattern.compile(\"^Insert\")),\n            Filters.regex(\"restaurant_id\", Pattern.compile(\"^restaurant\"))\n        )\n    )\n    collection.deleteMany(filter = queryParams).also {\n        println(\"Document deleted : ${it.deletedCount}\")\n    }\n}\n```\n\n## Summary\n\nCongratulations! You now know how to set up your first Kotlin application with MongoDB and perform CRUD operations. The complete source code of the\napp can be found on [GitHub](https://github.com/mongodb-developer/kotlin-driver-quick-start).\n\nIf you have any feedback on your experience working with the MongoDB Kotlin driver, please submit a comment in our\nuser [feedback portal](https://feedback.mongodb.com/) or reach out to me on Twitter: [@codeWithMohit](https://twitter.com/codeWithMohit).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Fkotlin-driver-quick-start","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongodb-developer%2Fkotlin-driver-quick-start","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-developer%2Fkotlin-driver-quick-start/lists"}