Navigation

Open and Close a Realm

Open a Synced Realm

To open a synced realm, call Realm.open(). Pass in a Configuration() object, which must include the sync property defining a SyncConfiguration object.

For example, to open a synced realm as the authenticated user “authedUser”, using partition “myPartition” and with a configuration that includes 3 schemas, your code might look similar to this:

const config = {
   schema: [schemas.TaskSchema, schemas.UserSchema, schemas.ProjectSchema],
   sync: {
      user: authedUser,
      partitionValue: myPartition,
   }
};

realm = await Realm.open(config);

Open a Local (Non-Synced) Realm

When opening a local (non-synced) realm, call Realm.open(), passing in a Configuration() object, which may include the path property defining the local file path to use when storing the data.

const config = {
   schema: [schemas.TaskSchema, schemas.UserSchema, schemas.ProjectSchema],
   path: "./myrealm/data"
};

realm = await Realm.open(config);

Close a Realm

It is important to remember to call the close() method when done with a realm instance to avoid memory leaks.

realm.close();
←   Relationships Reads  →