MongoDB Server-Side Kotlin Driver Now Generally Available
Kotlin is a language that has surged in popularity since it was first released in 2016. Developed at JetBrains, Kotlin is a cross-platform statically typed programming language that targets the JVM and interoperates with Java. Here at MongoDB, we are always looking for ways to enable developers from a broad range of programming language communities to have a great experience building with our products. To that end, we are delighted to announce that the official MongoDB server-side Kotlin driver is now generally available . Why we built a Kotlin Driver Though Kotlin has historically been known for Android development, about half of Kotlin developers are using the language for server-side use cases . Android, iOS, and Kotlin Multiplatform Mobile developers can use the Realm Kotlin SDK for their applications. However, given that a whopping half of all Kotlin developers are using the language for server-side, we’ve seen considerable user interest in an official Kotlin driver. As a language, Kotlin is also immensely popular. Kotlin holds the twelfth spot on the list of most desired languages (according to StackOverflow’s recent developer survey ). As a point of comparison, Java holds the tenth spot, just two above. Given the growing popularity of Kotlin and the strong community desire for an official server-side Kotlin driver, we decided to create a first-party Kotlin driver to fill this important need. Why use the MongoDB Kotlin Driver? The official MongoDB Kotlin driver makes it easy to use MongoDB with your Kotlin application. Not only do you get the benefits of interacting with MongoDB in a familiar language, you also get a complete library for building Kotlin applications in an idiomatic way, including support for coroutines, data classes, and serialization. What the driver can do With the new Kotlin driver, you get the benefits of working with MongoDB in your language of choice, while also knowing that the driver is supported by MongoDB officially. Let’s take a look at what you can do with the driver. Connect to MongoDB To use the MongoDB Kotlin driver for server-side development, you’ll need to have Kotlin installed and a MongoDB cluster set up. Once you’ve done that, you’ll want to retrieve your connection string. If you’re using MongoDB Atlas, you can find your connection string in the Atlas Web UI under the “Database” view by clicking the “Connect” button and then choosing Kotlin as your preferred language. To query your cluster from your application, create a data class to represent a MongoDB document and include that connection string in the class. You can find learn more in our documentation . Read from and write to MongoDB You can use the Kotlin Driver to perform CRUD operations on data stored in MongoDB. More information on how to perform CRUD Operations can be found here . We also have a quick reference guide available here . You can also use Builders – classes that simplify the process of using CRUD Operations and the MongoDB Query API. When using Builder classes, you can leverage the power of your IDE. The IDE can help you discover which methods are available to you, and can catch errors early on. Documentation on Builders can be found here . Convert between Kotlin Data Classes and MongoDB Data Formats True to their name, data classes in Kotlin are classes whose main property is to hold data. The compiler automatically derives several members based on the properties declared in the class's constructor. These members include equals() and hashCode(), toString(), and more. The Kotlin server-side driver natively supports encoding and decoding Kotlin data classes for MongoDB read and write operations using the default codec registry (a collection of classes that define how to encode and decode both Java and Kotlin types). You can insert and retrieve a data class as well as configure the serialization behavior of data classes using the Kotlin driver. You can find more information on data class support in the Kotlin driver here . Get started today Whether you’re new to Kotlin or already a Kotlin expert, try out the MongoDB Kotlin driver! To get started, simply find your connection string in MongoDB Atlas and follow our Quick Start guide . Once you’ve given it a try, please share your feedback with us through the MongoDB Feedback Engine . Your feedback helps us understand what features will make the most impact for our users. Head to the MongoDB.local hub to see where we'll be showing up next.