Fetching Firestore Collections & Documents

❗️

Deprecated

Firebase is no longer a first-party integration so these docs are only intended for legacy users

You can access your connected Firestore data using the following components under Lists & Data.

ComponentDescription
Firebase CollectionA component that is used in a screen's Layout to map a list of data from a Collection in Firestore.
Firebase DocumentA component that is used in a screen's Layout to read the data from a particular document under a Firestore Collection.
2032

Fetching a Collection

If you'd like to map a collection to a screen (for example, to populate a list of items), follow the steps:

  • Add a Firebase Collection component in the screen's Layout tree and select it.
  • From the Properties panel, select the name of the Firestore collection as a value to the Collection property.
2224

Then select the List component in the Layout tree. On the "Data" tab in the Properties panel, you'll select the Firebase Collection to map the data into this List.

2726

Where

The Where condition in a Firebase Collection allows you to map data to the list based on a condition. It takes three parameters:

  • a field to filter on
  • a comparison operator
  • a value

It has the following operators available:

OperatorDescripotion
==equal to
!=not equal to
<less than
<=less than or equal to
>great than
>=greater than or equal to
array-containsfilter result based on array values
array-contains-anyreturns documents where the given field is an array that contains one or more of the comparison values
inreturns documents where the given field matches any of the comparison values
not-inreturns documents where the given field exists is not null, and does not match any of the comparison values

For example, consider the Firestore document structure below. Each document in the collection books has a field rating that has some value.

1666

You can use the Where condition to display only those items in the list that has less than or equal to the rating value of 3.

1362

Order By

The Order By condition is used to sort the items in the List either in Ascending or Descending order. It takes two parameters:

  • a field to filter on
  • direction of to map values in the list
1362

Fetching a Document

Mapping a single document to a screen is similar to mapping a collection. If you'd like to map a document to a screen follow the steps:

  • Add a Firebase Document component in the screen's Layout tree and select it.
  • From the Properties panel, select the name of the Firestore collection as a value to the Collection property.
  • Select the Document id. It can be provided as a Navigation param, preferably, from a list on another screen where the data is being fetched from a Firestore collection.
2742

Next, choose the data-enabled component in the Layout tree that you want to map your document data to.

Here's an example of how to do this with a text component:

2736

Screen Level Data

Screen Level Data is another way to connect to fetch data from the Firestore. It's an alternate to Firebase Collection and Firebase Document components.

❗️

We only recommend you to use this option when you want to use Custom Code with Firebase.

To enable Screen Level Data, select the screen component and go to the Data tab in the Properties panel on the right-hand side. You will find the option to enable Screen Level Data.

2724

Click the Add Data button and

  • set the Source to **Firebase
  • set the Type to a Firestore Collection or Document
  • set the Collection/Document you want to fetch data in the screen
1350

Fetching data, using Where and Order By conditions work in the same way as descrbied above.

Additional Resources