Connect to a Database
Connecting a Database using the Database Hub allows you to have access to the connected 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
The very first step is to find a database that suits your needs and is publicly shared in Back4app. You can go to the Database Hub list of databases and search for any topic that interests you.
Once you find the database that you want, you can proceed.
For this tutorial I am going to use this Database of World Continents, Countries and Cities:
Step 2 - Connecting
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.
If your connection succeeded, you should see this dialog:
Step 3 - Using the data
Once connected, 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.