Realm.Sync

When opening a Realm created with Realm Mobile Platform v1.x, it is automatically migrated to the v2.x format. In case this migration is not possible, an exception is thrown. The exception´s message property will be equal to IncompatibleSyncedRealmException. The Realm is backed up, and the property configuration is a {Realm~Configuration} which refers to it. You can open it as a local, read-only Realm, and copy objects to a new synced Realm.

Related Classes

Adapter
AuthError
ChangeEvent
IncompatibleSyncedRealmError
Session
User
Realm.Sync.addListener(server_url, admin_user, regex, name, change_callback)
static

Add a sync listener to listen to changes across multiple Realms

Parameters:
  • server_url
    • Type: string
    • the sync server to listen to

  • admin_user
    • Type: SyncUser
    • an admin user obtained by calling new Realm.Sync.User.adminUser

  • regex
    • Type: string
    • a regular expression used to determine which changed Realms should trigger events - Use .* to match all all Realms

  • name
    • Type: string
    • The name of the event that should trigger the callback to be called Currently only the 'change' event is supported

  • change_callback
    • Type: function
    • called when changes are made to any Realm which match the given regular expression

Realm.Sync.initiateClientReset(path)
static

Initiate a client reset. The Realm must be closed prior to the reset.

Parameters:
  • path optional
    • Type: string
    • The path to the Realm to reset. Throws error if reset is not possible.

Example:
{
  const config = { sync: { user, url: 'realm://localhost:9080/~/myrealm' } };
  config.sync.error = (sender, error) => {
    if (error.name === 'ClientReset') {
      Realm.Sync.initiateClientReset(original_path);
      // copy required objects from Realm at error.config.path
    }
  }
}
Realm.Sync.removeAllListeners(name)
static

Remove all previously regiestered listeners

Parameters:
  • name optional
    • Type: string
    • The name of the event whose listeners should be removed. Currently only the 'change' event is supported

Realm.Sync.removeListener(regex, name, change_callback)
static

Remove a previously registered sync listener

Parameters:
  • regex
    • Type: string
    • the regular expression previously used to register the listener

  • name
    • Type: string
    • The event name Currently only the 'change' event is supported

  • change_callback
    • Type: function
    • the previously registered callback to be removed

Realm.Sync.setLogLevel(log_level)
static

Set the sync log level.

Parameters:
  • log_level
    • Type: string
LogLevel
Type:
"error" or "info" or "debug"