Unable to partially Sync Realm(Possible conflict with multiple realms)


#1

I am unable to get the Partial Sync Realm Working
I am currently running two Realms in my codebase(A local realm to act as a local Cache) And a partially synced realm that syncs data from Realm cloud.

//Open local Config realm
function openLocal() {
  return new Realm({
    schema: [Config],
    schemaVersion: 1,
    path: 'localRealm.realm'
  });
}

function getSyncedConfig(user, syncUrl) {
  return user.createConfiguration({
    schema: [Drivers, Passengers],
    path: 'syncedRealm.realm',
    schemaVersion: 2,
    sync: {
      url: syncUrl,
      user
    }
  });
}

//Opem partially synced realm
function openSynced(apiKey) {
  return new Promise((resolve, reject) => {
    const user = Realm.Sync.User.current;
    const realmUrl = 'https://myrealmurl';
    let syncUrl =
      'realms:/myrealmurl/realm-db/default';
    if (user) {
      try {
        const realm = Realm.open(getSyncedConfig(user, syncUrl))
          .progress((transferred, transferable) => {
            console.log('TCL: openSynced -> transferred', transferred);
          })
          .then(realm => {
            console.log('TCL: openSynced -> realm', realm);
            resolve(realm);
          })
          .catch(e => {
            reject(e);
          });
      } catch (e) {
        reject(e);
      }
    } else {
      loginRealm(realmUrl, apiKey).then(newUser => {
        try {
          const realm = Realm.open(getSyncedConfig(newUser, syncUrl))
            .progress((transferred, transferable) => {})
            .then(realm => {
              resolve(realm);
            })
            .catch(e => {
              reject(e);
            });
        } catch (e) {
          reject(e);
        }
      });
    }
  });
}

//Set up local and synced realm
  const realmLocal = openLocal();
  const config = localRealm.objects('Config')[0];
  const [runOnce, setOnce] = useState(0);

  async function runSync() {
    if (runOnce === 0) {
      setOnce(1);
      openSynced(apiKey)
        .then(syncedRealm => {
          let objs = syncedRealm.objects('drivers');
          let sub = objs.subscribe();
          sub.addListener((subscription, state) => {
            switch (state) {
              case Realm.Sync.SubscriptionState.Complete:
                console.log('TCL: Completed');
                break;
              case Realm.Sync.SubscriptionState.Pending:
                console.log('TCL: Pending ');
                break;
              case Realm.Sync.SubscriptionState.Error:
                console.log('TCL:An error occurred: ', subscription.error);
                break;
            }
          });
        })
        .catch(error => console.log('TCL: ', error));
    }
  }
  runSync();

I have been stuck on this issue for a week now and dont know what else to try? Could you please give some assistance? I have tried using both the ‘new Realm’ and ‘Realm.open’ API’s.

At the moment the only subscription state that the code runs is ‘Pending’.

I have also tried reinstalling the app, creating a new instance of realm cloud, setting different schema versions?

Could It be a conflict between the local realm and the synced realm

I get this log from Realm clouds logger-
Open files in Realm Object Server: {"regular":27,"directory":0,"character-device":3,"block-device":0,"pipe":21,"symbolic-link":0,"socket":19,"unknown":8,"total":78} Im not sure if the issue is with the 'unkown variable? Thanks