Docs Menu

Open a Synced Realm - Kotlin SDK

On this page

  • Prerequisites
  • Open a Synced Realm
  • Configure a Synced Realm
Note
Flexible Sync

The Kotlin SDK does not yet support Flexible Sync. You can currently only use the SDK with Partition-Based Sync applications.

Before you can access a synced realm from the client, you must:

  1. Enable sync in the Realm UI.
  2. Install the sync distribution of the Kotlin SDK for Android or Kotlin Multiplatform.
  3. Authenticate a user in your client project.

To open a synced realm, pass a user, a partition, and a set of Realm object schemas to SyncConfiguration.Builder(). Then, pass the configuration to Realm.open() to open an instance of the realm:

val app = App.create(YOUR_APP_ID)
runBlocking {
val user = app.login(Credentials.anonymous())
val config = SyncConfiguration.Builder(user, PARTITION, setOf(/*realm object models here*/))
// specify name so realm doesn't just use the "default.realm" file for this user
.name(PARTITION)
.build()
val realm = Realm.open(config)
Log.v("Successfully opened realm: ${realm.configuration.name}")
realm.close()
}

To adjust specific configuration settings, use the options provided by SyncConfiguration.Builder:

val app = App.create(YOUR_APP_ID)
runBlocking {
val user = app.login(Credentials.anonymous())
val config = SyncConfiguration.Builder(user,PARTITION, setOf(/*realm object models here*/))
.maxNumberOfActiveVersions(10)
.build()
val realm = Realm.open(config)
Log.v("Successfully opened realm: ${realm.configuration}")
realm.close()
}
←  Sync Overview - Kotlin SDKApp Services - Kotlin SDK →
Give Feedback
© 2022 MongoDB, Inc.

About

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