Docs Menu

MongoDB Realm Kotlin SDK (Beta)

On this page

  • Local Realm Database
  • Define an Object Schema
  • Query Realm Database
  • Update Objects
  • Get Started
Note
Beta Release

This SDK is currently offered as a beta release. We encourage you to try out the feature and give feedback. However, be aware that APIs and functionality are subject to change.

The MongoDB Realm Kotlin SDK allows you to use Realm Database from:

Note
Sync Support In Development

The SDK currently supports some, but not all, Realm Sync functionality. For more information about supported behavior, see the API reference.

With the MongoDB 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))
.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 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

To start using the MongoDB 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 - React Native SDKInstall (Kotlin SDK) →
Give Feedback
© 2022 MongoDB, Inc.

About

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