Mobi Builder


Firebase cloud

What is firebase?

Firebase is a Backend-as-a-Service (BaaS). Firebase allows you to create a cloud database. This can allow you to store and retrieve user generated content alongside many other uses. Firebase also offers a variety of other features but currently Mobi Builder only supports cloud firestore and cloud functions (you would use HTTP requests for this). Firebase offers two databases - realtime database and firestore. Firestore is the successor of the realtime database and is faster.



Get set up on firebase

First, create a firebase account. You can login with your Google account at firebase.google.com, then create a project after going to your firebase console. Click the 'add project' button. Next, fill in all of the required information in order to create a project. Take a note of your project id as you will need it later.

After reaching your project dashboard, click the settings icon at the top right of your screen. Click 'project settings'. You should take a note of the web API key. Next, click 'database' and create a cloud firestore database (not a realtime database).



Initialize firebase in Mobi Builder

Using the web API key and the project id that you recorded earlier (in the get set up on firebase section), you will need to complete the following block:

You will need to do this every time before using firebase.



Writing to the database

There are multiple methods of writing to the firebase database. If you use the set method, existing data will be overwritten. Instead, if you use the update method, data will be updated and other data will not be overwritten. You will need to specify the collection and document that you are trying to access. You will also need to provide a JSON string containing the data that you wish to store.



Reading the database

You will need to specify the collection and document that you are trying to access. All fields of that document will be returned as a object in the local variable data. You will need to create the variable data if you wish to use it. Alternatively, if there is an error, the error information will be stored in the variable error. Again, you will need to create this variable if you wish to use it.