3

I ask myself lots of questions about the choice of databases for my future react-native application, because I would like a local database that stores the static data of the application. I would like also to store the data created by the user on a data server.

  1. I thought using Realm for local storage
  2. MongoDB for remote storage

Problem: I do not know how to synchronize remote data, because when the user is offline, I want the data to be stored locally and then when it goes offline, I want the data to be sent to the server

Can these two databases be used mutually, or is MongoDB able to store the data locally?

2 Answers 2

2

Consider using AsyncStoragefor local storage, andAppState to sync it with your db of choice (mongoDB is a good remote choice, but doesn't work locally). They're both native modules. AsyncStorage works like localStorage. When the app transitions from foreground to background is a good time to save data locally and remotely. It looks like this.

      _handleAppStateChange = (nextAppState) => {
if (this.state.appState.match(/inactive|background/) && nextAppState === 'active') {
  console.log('App has come to the foreground!')
  this.setState({appState: AppState.currentState});
} 
else if (this.state.appState.match(/active|background/) && nextAppState === 'inactive') {
  console.log('App has gone to background!')
   this.setState({appState: AppState.currentState});
}    


}

The documentation is excellent.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I'm going to watch this !
1

I am not sure how many data will you treat in local database, but MongoDB Stitch can be the one of solutions.

Stitch Mobile Sync.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.