React native android/iOS app stop with data sync process from mongoDB

I’m working on the device sync functionality with mongoDB to react-native app (realm). I’ve added the initialSubscription for the sync mongoDB data into realm database. App is stop after the sync data.

RealmAppProvider.js

const realmContext = createRealmContext({
  schema: [
    playlistSchema
  ],
});

const { RealmProvider } = realmContext;
const RealmAppProvider = (props) => {
  ...
  return (
    <AppProvider id={appId} baseUrl={baseUrl}>
      <UserProvider fallback={RealmAuth}>
        <RealmProvider
          sync={{
            flexible: true,
            initialSubscriptions: {
              rerunOnOpen: true,
              update(subs, realm) {
                subs.add(realm.objects(playlistSchema))
              },
            },
            onError: errorCallback,
          }}
          fallback={LoadingIndicator}
        >
          {props.children}
        </RealmProvider >
      </UserProvider>
    </AppProvider>
  )
}

App.js

const App = () =>{
...
 return (
    <RealmAppProvider>
      <View style={appStyles.flexContainer}>
        <StatusBar
          backgroundColor={appTheme.colors.background}
          barStyle={Appearance.getColorScheme() == 'dark' ? 'light-content' : 'dark-content'}
        />
        <PaperProvider theme={appTheme}>
          <AppProvider>
            <SafeAreaProvider>
              <NavigationContainer ref={navigationRef}>
                <Navigation navigationRef={navigationRef} />
              </NavigationContainer>
            </SafeAreaProvider>
          </AppProvider>
        </PaperProvider>
        <Toast config={toastConfig} />
      </View >
    </RealmAppProvider>
  );
}

Attached the console log image when app stops.

Hello, MongoDB community

I’ve been stuck on the above issue for a long time. Could you check my query and advise me on this section? It would be very useful to me.

Thanks.

@mongo_dba @mongo_learn @Tyler_Kaye @Mansoor_Omar

Hi, can you please elaborate on what you mean by the app is stopping working? The logs don’t show anything out of the ordinary, and I am not quite sure of the details of the behaviour you are describing. Also, if you can post a link to your application in realm.mongodb.com, I can see if anything looks off in the backend logs.

Best,
Tyler

Hello @Tyler_Kaye ,

I apologise for the delay in responding.

I’ve configured <UserProvider> and <RealmProvider> with required configs. We are currently using Realm.Credentials.apiKey based authentication, and the app is working fine for the authentication stage.

After successful authentication, the RealmProvider configuration will be executed; for sync, I’ve integrated the following configuration.

sync={{
  flexible: true,
  initialSubscriptions: {
    update(subs, realm) {
      subs.add(realm.objects(playlistSchema))
    },
  },
  onError: errorCallback,
}}

With the config application is able to fetch the data from mongo and write into device realmDB, After the complete process app will close automatically from foreground. When i’m restart the app it’s working fine.
Sync starts only if I use initialSubscriptions, If we’re using ‘rerunOnOpen: true’ then app is close on every launch because it fetches all data from the beginning.

Our realm app URL is https://realm.mongodb.com/groups/650a789571fbe30a95085905/apps

Hi Tyler,

Dhaval and I work together on this project. We haven’t been able to figure this out yet. Any guidance to get over this hump would be really appreciated. Thanks in advance.

Happy holidays.

Best,
Pankaj

Hey everyone, Andrew from the JS team here. I’m curious if you can provide some more information about the crash that is occurring. Is it possible to get crashlogs for iOS or a stack trace in out of logcat for Android?
All the code posted so far looks fine and I don’t see any reason why it would crash.