Docs Menu

Class SyncConfiguration

On this page

java.lang.Object
io.realm.mongodb.sync.SyncConfiguration

A SyncConfiguration is used to setup a Realm Database that can be synchronized between devices using MongoDB Realm.

A valid User is required to create a SyncConfiguration . See Credentials and App.loginAsync(Credentials, App.Callback) for more information on how to get a user object.

A minimal SyncConfiguration can be found below.

App app = new App("app-id");
User user = app.login(Credentials.anonymous());
SyncConfiguration config = SyncConfiguration.defaultConfiguration(user, "partition-value");
Realm realm = Realm.getInstance(config);

Synchronized Realms only support additive migrations which can be detected and performed automatically, so the following builder options are not accessible compared to a normal Realm:

  • deleteRealmIfMigrationNeeded()
  • migration(Migration)

Synchronized Realms are created by using Realm.getInstance(RealmConfiguration) and Realm.getDefaultInstance() like ordinary unsynchronized Realms.

Tip
See also:
  • The docs for more information about the two types of synchronization.
Modifier and Type
Class and Description
public static final
Modifier and Type
Method and Description
public static SyncConfiguration
User user,
ObjectId partitionValue
)

Returns a default configuration for the given user and partition value.

public static SyncConfiguration
User user,
Integer partitionValue
)

Returns a default configuration for the given user and partition value.

public static SyncConfiguration
User user,
Long partitionValue
)

Returns a default configuration for the given user and partition value.

public static SyncConfiguration
User user,
String partitionValue
)

Returns a default configuration for the given user and partition value.

public boolean
public static RealmConfiguration
String canonicalPath
)

Returns a RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes.

public static RealmConfiguration
String canonicalPath,
byte[] encryptionKey,
)

Returns a RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes.

Returns the Client Reset handler for this SyncConfiguration.

Returns the error handler for this SyncConfiguration.

Returns the transaction instance with initial data.

public long

Returns the timeout defined when downloading any initial data the first time the Realm is opened.

public BsonValue

Returns the value this Realm is partitioned on.

public URI

Returns the server URI for the remote MongoDB Realm the local Realm is synchronizing with.

public OsRealmConfig.SyncSessionStopPolicy

NOTE: Only for internal usage.

public String

Returns the url prefix used when establishing a sync connection to the Realm Object Server.

public User

Returns the user.

public int
protected boolean
protected boolean

Checks if the Realm file defined by this configuration already exists.

public boolean

Returns true if the Realm file must be deleted once the User owning it logs out.

public boolean

Returns true if the Realm will download all known changes from the remote server before being opened the first time.

public String
  • Methods inherited from class java.lang.Object : getClass , hashCode , equals , clone , toString , notify , notifyAll , wait , wait , wait , finalize
  • Methods inherited from class io.realm.RealmConfiguration : getRealmDirectory , getRealmFileName , getEncryptionKey , getSchemaVersion , getMigration , shouldDeleteRealmIfMigrationNeeded , getDurability , getSchemaMediator , getInitialDataTransaction , getCompactOnLaunchCallback , getRealmObjectClasses , getPath , realmExists , getRxFactory , getFlowFactory , isReadOnly , isRecoveryConfiguration , getMaxNumberOfActiveVersions , isAllowWritesOnUiThread , isAllowQueriesOnUiThread , equals , hashCode , createSchemaMediator , toString , isSyncConfiguration , forRecovery
User user,
ObjectId partitionValue
)

Returns a default configuration for the given user and partition value.

Parameters

  • user - The user that will be used for accessing the Realm App.
  • partitionValue - The partition value identifying the remote Realm that will be synchronized.

Returns

the default configuration for the given user and partition value.

User user,
Integer partitionValue
)

Returns a default configuration for the given user and partition value.

Parameters

  • user - The user that will be used for accessing the Realm App.
  • partitionValue - The partition value identifying the remote Realm that will be synchronized.

Returns

the default configuration for the given user and partition value.

User user,
Long partitionValue
)

Returns a default configuration for the given user and partition value.

Parameters

  • user - The user that will be used for accessing the Realm App.
  • partitionValue - The partition value identifying the remote Realm that will be synchronized.

Returns

the default configuration for the given user and partition value.

User user,
String partitionValue
)

Returns a default configuration for the given user and partition value.

Parameters

  • user - The user that will be used for accessing the Realm App.
  • partitionValue - The partition value identifying the remote Realm that will be synchronized.

Returns

the default configuration for the given user and partition value.

public boolean equals (
)

Overrides

equals in class RealmConfiguration

String canonicalPath
)

Returns a RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes. This is useful when trying to open a backup/recovery Realm (after a client reset). Note: This will use the default Realm module (composed of all RealmModel ), and assume no encryption should be used as well.

Parameters

  • canonicalPath - the absolute path to the Realm file defined by this configuration.

Returns

RealmConfiguration that can be used offline

String canonicalPath,
byte[] encryptionKey,
)

Returns a RealmConfiguration appropriate to open a read-only, non-synced Realm to recover any pending changes. This is useful when trying to open a backup/recovery Realm (after a client reset).

Parameters

  • canonicalPath - the absolute path to the Realm file defined by this configuration.
  • encryptionKey - the key used to encrypt/decrypt the Realm file.
  • modules - if specified it will restricts Realm schema to the provided module.

Returns

RealmConfiguration that can be used offline

Returns the Client Reset handler for this SyncConfiguration.

Returns

the Client Reset handler.

Returns the error handler for this SyncConfiguration.

Returns

the error handler.

Returns the transaction instance with initial data.

Returns

the initial data transaction.

Overrides

getInitialDataTransaction in class RealmConfiguration

Returns the timeout defined when downloading any initial data the first time the Realm is opened.This value is only applicable if shouldWaitForInitialRemoteData() returns true .

Returns

the time Realm will wait for all changes to be downloaded before it is aborted and an exception is thrown.

public BsonValue getPartitionValue ()

Returns the value this Realm is partitioned on. The partition key is a property defined in MongoDB Realm. All classes with a property with this value will be synchronized to the Realm.

Returns

the value being used by MongoDB Realm to partition the server side MongoDB Database into Realms that can be synchronized independently.

public URI getServerUrl ()

Returns the server URI for the remote MongoDB Realm the local Realm is synchronizing with.

Returns

URI identifying the MongoDB Realm this local Realm is synchronized with.

public OsRealmConfig.SyncSessionStopPolicy getSessionStopPolicy ()

NOTE: Only for internal usage. May change without warning. Returns the stop policy for the session for this Realm once the Realm has been closed.

Returns

the stop policy used by the session once the Realm is closed.

Returns the url prefix used when establishing a sync connection to the Realm Object Server.
public User getUser ()

Returns the user.

Returns

the user.

public int hashCode ()

Overrides

hashCode in class RealmConfiguration

protected boolean isSyncConfiguration ()

Overrides

isSyncConfiguration in class RealmConfiguration

protected boolean realmExists ()

Checks if the Realm file defined by this configuration already exists.WARNING: This method is just a point-in-time check. Unless protected by external synchronization another thread or process might have created or deleted the Realm file right after this method has returned.

Returns

true if the Realm file exists, false otherwise.

Overrides

realmExists in class RealmConfiguration

public boolean shouldDeleteRealmOnLogout ()

Returns true if the Realm file must be deleted once the User owning it logs out.

Returns

true if the Realm file must be deleted if the User logs out. false if the file is allowed to remain behind.

Returns true if the Realm will download all known changes from the remote server before being opened the first time.

Returns

true if all remote changes will be downloaded before the Realm can be opened. false if the Realm can be opened immediately.

public String toString ()

Overrides

toString in class RealmConfiguration

←  Class Sync.DebugClass SyncConfiguration.Builder →
Give Feedback
© 2022 MongoDB, Inc.

About

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