Realm Kotlin SDK
On this page
The Realm Kotlin SDK allows you to use Realm Database and Device Sync from:
- Android and iOS applications written with Kotlin Multiplatform Mobile (KMM)
- standalone Android applications
Local Realm Database
With the Realm Kotlin SDK, you can access objects stored in a local instance of Realm Database. With Realm Database, you can:
Define an Object Schema
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 Realm Database
Query for stored objects:
val config = RealmConfiguration.Builder(schema = setOf(Frog::class)) .build() val realm = Realm.open(config) 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
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)) .build() val realm = Realm.open(config) // 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") .first() .find() // 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
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.
Get Started
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.