Download and Install
This guide demonstrates how to create a project and add the Kotlin Sync driver dependencies by using Gradle or Maven.
Create a Kotlin Project
First, make sure that your system has Kotlin installed and running on JDK 1.8 or later.
We recommend that you use an integrated development environment (IDE) such as IntelliJ IDEA or Eclipse IDE to configure Gradle or Maven to build and run your project.
Tip
If you are not using an IDE, see the Creating New Gradle Builds guide or the Building Maven guide for more information on how to set up your project.
For more information on getting started with Kotlin and creating your first project, see Get started with Kotlin/JVM in the Kotlin language documentation.
Add MongoDB as a Dependency
If you are using Gradle to manage your
packages, add the following entry to your build.gradle.kts
dependencies list:
dependencies { implementation("org.mongodb:mongodb-driver-kotlin-sync:5.2.0") }
If you are using Maven to manage your
packages, add the following entry to your pom.xml
dependencies list:
<dependencies> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongodb-driver-kotlin-sync</artifactId> <version>5.2.0</version> </dependency> </dependencies>
After you configure your dependencies, ensure that they are available to your project by running the dependency manager and refreshing the project in your IDE.
Add Serialization Library Dependencies
To enable the driver to convert between Kotlin objects and BSON, the data format for documents in MongoDB, you must also add one or both of the following serialization packages to your application:
bson-kotlinx
(Recommended)bson-kotlin
If you are using Gradle to manage your packages, add one of the following
entries to your build.gradle.kts
dependencies list:
implementation("org.mongodb:bson-kotlinx:5.2.0") // OR implementation("org.mongodb:bson-kotlin:5.2.0")
If you are using Maven to manage your packages, add one of the following
entries to your pom.xml
dependencies list:
<dependency> <groupId>org.mongodb</groupId> <artifactId>bson-kotlinx</artifactId> <version>5.2.0</version> </dependency> <!--OR--> <dependency> <groupId>org.mongodb</groupId> <artifactId>bson-kotlin</artifactId> <version>5.2.0</version> </dependency>
After you configure your dependencies, ensure that they are available to your project by running the dependency manager and refreshing the project in your IDE.
After you complete these steps, you have a new project directory and the driver dependencies installed.
Note
If you run into issues on this step, ask for help in the MongoDB Community Forums or submit feedback by using the Rate this page tab on the right or bottom right side of this page.