Connect to a Database
Connecting a Database using the Database Hub allows you to have access to the source database structure and data from inside your App in Back4app.
This ensures any new updates for schemas and/or data are immediately delivered to your App so everything is up to date at any given moment.
This is also useful when big (a.k.a. in huge) databases are available, allowing you to use its data without having to fully copy the database to your account.
In order to use or share a database, you will need:
- An app created at Back4App.
- See the Create New App tutorial to learn how to create an app at Back4App.
Step 1 - Find a Database to connect
Go to the Database Hub list of databases and search for any topic that interests you.
For this tutorial, will be used the Database of World Continents, Countries and Cities:
Step 2 - Connect
Connect button on the top right corner of the screen. The counter on the right side shows how many Apps are using that database at the moment:
The Connect dialog will appear. Then choose to which App, from one of your already existing apps, you want to connect. The chosen App in the drop down will have access to the Database that you are connecting to.
Then, success message will appear:
Step 3 - Use the data
Go to the Dashboard of the App you connected. You will notice the classes from the connected Database appear in the Database Browser in the following formats:
DatabaseName_ClassName if it is a custom class
DatabaseName__ClassName if it is a Parse class
The difference is that Parse classes have two
_ between the DatabaseName and ClassName:
From now on you can query the data of the connected classes on your code, the API Console, the GraphQL console and even make
pointers among your App’s classes and the connected ones.