Docs Menu

Realm Kotlin SDK

On this page

  • Local Realm Database
  • Define an Object Schema
  • Query Realm Database
  • Update Objects
  • Atlas App Services
  • Get Started

The Realm Kotlin SDK allows you to use Realm Database and Device Sync from:

With the Realm Kotlin SDK, you can access objects stored in a local instance of Realm Database. With Realm Database, you can:

Define your object schema with marked Kotlin classes:

class Frog : RealmObject {
var name: String = ""
var age: Int = 0
var species: String? = null
var owner: String? = null

Query for stored objects:

val config = RealmConfiguration.Builder(schema = setOf(Frog::class))
val realm =
val tadpoles: RealmQuery<Frog> = realm.query<Frog>("age > $0", 2)
Log.v("Tadpoles: ${tadpoles.count()}")
val numTadpolesNamedJasonFunderburker = tadpoles.query("name == $0", "Jason Funderburker").count()
Log.v("Tadpoles named Jason Funderburker: $numTadpolesNamedJasonFunderburker")

Update objects in Realm Database by updating field values on an instance of the object within a transaction:

val config = RealmConfiguration.Builder(schema = setOf(Frog::class))
val realm =
// start a write transaction
realm.writeBlocking {
// get a frog from the database to update
val frog: Frog? = query<Frog>()
.query("name == $0 LIMIT(1)",
"Benjamin Franklin")
// update the frog's properties
frog?.apply {
name = "George Washington"
species = "American bullfrog"
} // when the transaction completes, the frog's name and species
// are updated in the database

Atlas App Services is a backend for client applications hosted by MongoDB in the cloud. Individual backends, known as Apps, provide the ability to synchronize data stored in Realm Database as well as a layer of backend functionality including user accounts and backend logic. The SDK optionally contains the ability to access these Apps running in the cloud.

To start using the Realm Kotlin SDK in your application, see the installation guide for Kotlin Multiplatform or Android. Once you've installed the SDK, check out the Quick Start.

←  Upgrade from Stitch to Realm - Java SDKInstall - Kotlin SDK →
Give Feedback
© 2022 MongoDB, Inc.


  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.