Skip to main content

client.realm

Realms group objects, areas, subscriptions and instructions together. To learn more about them, head over to our guide on core concepts.

client.realm.create(id, label, data)

Creates a new realm. Returns a promise that resolves once the realm creation succeeded.

  • id a unique id for this realm
  • label a name for this realm
  • dataan optional map of metadata to be associated with this realm

client.realm.get(id)

Retrieves an existing realm. Returns a promise resolving to a realm object.

tip

We recommend that you retrieve the realm object only once, using client.realm.get(id), and then share it or make it accessible throughout your app by passing it around, turning it into a service, or by sticking it onto a global object.

// retrieving an object
const realm = await client.realm.get('realm-Yid0WHuy9a7-3kwNL8Ltq');
const object = await realm.object.get('obj-c4UO206FxjG4oK6UAb3od');

client.realm.list()

Returns a promise that resolves to a list of realms an

const realmList = await client.realm.list();
/*
realmList = {
"realm-hL-D590PXa6jqLyTuMtAw": {
"id": "realm-hL-D590PXa6jqLyTuMtAw",
"label": "Building Site 14",
"objects": 14,
"areas": 4,
"instructions": 1,
"subscriptions": 4
},
"realm-cgXkx319fiqELLdAoK4rK": {
"id": "realm-cgXkx319fiqELLdAoK4rK",
"label": "Building Site 23",
"objects": 131,
"areas": 17,
"instructions": 4,
"subscriptions": 22
},
}
*/

client.realm.delete()

Deletes an existing realm. Returns a promise that resolves once the deletion is completed.

client.realm.subscribe()

Returns a subscription that notifies you whenever realms are created, updated or deleted.

const subscription = await client.realm.subscribe();
subscription.on('update', realmList => {
//...
});