Firestore Data (legacy)
Last updated
Last updated
This element is decrecated an it is kept on the plugin for backwards compatibility purpose.
We suggest using the new element for a better experience and since this one might be eventually removed from the plugin in future versions.
The Firestore Data element can be used to fetch document data from Firestore as a list, single document* or a count**.
Here you must specify the id (or name) of the collection you want to query data from. You can subcollections paths to choose a subcollection (e.g. collection/doc_id/subcollection).
The plugin will query data from the Firestore, running front-end process on Bubble. That way, no Workload units will be consumed. 🙂
List Performs a query for a list of documents from the Firestore Collection you've specified. It also applies the query and front-end filters defined on the element's settings.
Single Performs a single document query from Firestore, in the collection and document id you specified. Filters won't be applied to single document queries.
Count Performs a document count query from Firestore, respecting the query filters you defined. Obs.: Each 1000 blocks of document accounted for will be billed as 1 document read on Firestore (e.g. 1500 documents counted will be billed for 2 reads).
List and Count Performs both List and Count queries. That way you can use the "(list) documents data" and "(count) number of documents" state at once.
The ID of the document you want to get from Firestore.
If checked, document data won't update dynamically.
If left unchecked, documents on List and Single queries will update responding to changes on the backend. Each document updated or removed from a list will account for a document read of Firebase's billing.
You can choose a field to order your list of document from, at query level, specifying the sort direction (descending = yes | ascending = no).
When doing a sorted query for the first time, you might be confronted with an alert asking you to create an index for that query. That's a Firestore feature that creates different indexes for the database, which makes queries lighting fast.
To configure the new index, you need only access the link provided on the browser's console (press F12). After a couple of minutes, refresh the page and the query should work.
On the query sorting options, you can also specify a "Page Size" for the query, which allows you to work with pagination and can help you save document reads.
When you define a page size of 8, for instance, the query will only get the first 8 occurrences of the query you configured. That's why this option works only when you have a defined order for the data.
To change pages on the list, you can you the actions:
(list) show next page at a Firestore Data
(list) show previous page at a Firestore Data
Pagination on dynamic queries that on which the order of document's changes a lot may lead to unwanted behaviors, such as documents disappearing and returning only after you reload the page or the Firestore Data element. That's because of how pagination works on Firestore, as it uses other document's as reference for each page.
For instance, it you have 8 documents and one of them updates to the 9th position, since the next page starts at the current 10th document, this updated document might stay on a "limbo" in which it won't show unless you refresh the page or the Firestore Data element. This only happens if you had already loaded the 2nd page.
This options allow you to choose fields from which to filter your query.
If you have security rules set to allow only the "owner" of a document to see it, for instance, you'll need to add a query filter to get only document's where the field "owner" equals the current user's reference.
You can choose to ignore empty constraints, which will simple "skip" the filter if the input you provided is empty. Keep in mind that in some cases this may require Firestore to create indexes for each filtering configuration.
<
Gets values less than the provided input (must be of type number or date)
<=
Gets values less than or equal to the provided input (must be of type number or date)
==
Gets values equal to the provided input.
>
Gets values greater than the provided input (must be of type number or date).
>=
Gets values greater than or equal to the provided input (must be of type number or date).
array-contains
Gets values where the field of type array/list has the value provided as input.
array-contains-any
Gets values where the field of type array/list any of the array of values provided as input.
in
Gets values where the field value is present on the array of values provided as input.
not-in
Gets values where the field value is not present on the array of values provided as input.
Firestore supports only one filter of type "array-contains", "array-contains-any", "in" or "not-in" per query. If you try to use more than one, the first one will be considered by the plugin, but the other's will be ignored.
Since Bubble is not flexible on the type of data we can define on plugins, the best way to implement our plugin was to work with texts. So each value you put on query values must be interpreted the right way to perform the Firestore Query. Defining a "query filter value type" can help us get it right.
So here are the types of query filter values:
auto
The plugin will try to infer the type from the input you provided.
text
Treated as a text value.
number
Treated as a number value.
boolean (true/false)
Treated as a true or false (yes/no) value.
date
Treated as a Date type. The plugin will convert the value to a Date.
array
Treated as a list in JavaScript format (e.g. ["item1", "item2", "item3"]). If you need to use it on Bubble's lists, you can apply the ":format as text" message to the list, to build the array string into that format.
reference (coll/doc_id)
Treated as a document reference. Document references are always handled by the plugin as paths to a document. For instance, if you want to get the reference for a document from the "tasks" collection with an id "1234", you should right "tasks/1234"
Once data is fetched from Firestore, the plugin allows you to perform front-end operations without the need to query data again. This is ideal for performing fast sorting or filters as a reaction from input value changed on the user's UI.
==
Gets values equal to the provided input.
<>
Gets values not equal to the provided input.
>=
Gets values greater than or equal to the provided input (must be of type number or date).
>
Gets values greater than the provided input (must be of type number or date).
<=
Gets values less than or equal to the provided input (must be of type number or date)
<
Gets values less than the provided input (must be of type number or date)
contains
Gets values where the field of type array/list has the value provided as input.
contains-any
Gets values where the field of type array/list has any of the array of values provided as input.
contains case sensitive
Gets values where the field of type array/list has the value provided as input, but differentiating uppercase from lowercase characters.
doesn't contain
Gets values where the field of type array/list doesn't have the value provided as input.
doesn't contain case sensitive
Gets values where the field of type array/list doesn't have the value provided as input, but differentiating from uppercase and lowercase characters.
is in
Gets values where the field value is present on the array of values provided as input.
isn't in
Gets values where the field value is not present on the array of values provided as input.
isn't empty / count > 0
Gets values where the field value doesn't exist, is empty or, if it's an array/list, its length is zero.
is empty / count = 0
Gets values where the field value exists, is not empty or, if it's an array/list, its length is greater than zero.
You can provide the names of the fields on the list of document's you'd like to get as a list on Bubble.
For each field you choose to fetch from the document, you must specify the type of data Bubble should try to receive.
In some cases, more than one type can be applied, like in boolean values, that you can get as "text" or "yes/no". In other cases you must be careful to declare the right value, or error can occur, like when you try to declare a "number" for a "text" value.
This option allows you to merge fields of type list in one single list.
For instance, if you have two documents with a field named "tags", that has a list of texts (one ["tag1"] and the other ["tag1", "tag2]), this option will merge them as ["tag1", "tag1", "tag2"] instead of bringing two array values as texts (i.e. ["tag1"], ["tag1", "tag2"]).
This option will make the list of values ignore the front-end filters applied to them.
This is useful when you want to use this list to feed the choices source of a Dropdown or input that you want to use as a front-end filter. If you leave this option unchecked, the choices sorce would be filtered too.
The Firestore Data element provides states according to the query type you chose on it's settings.
The name of the collection from which the element is getting it's data from.
If the query fails and returns an error, the error message will be stored on this state.
A list of texts contains the IDs of the document fetched from a "List" or "List and Count" type of queries.
Lists of fields you chose to retrieve from the documents list, with filters already applied.
Turns to "yes" when all the element's states are done being filled, an "no" when they are being filled.
Although this operations are fast, the fact the they are filled in order and not at the same time may lead to issues, that's why this state was created.
This action reloads the elements data, performing queries again. This might be useful to provide consistency in your data.
This action allows you to add, remove or refresh the count query of a Firestore Data element.
On static queries, though we don't need to have them listen for changes all the time, updating a single document on it might be needed sometimes. Because of that we provide this update action for you to specify a document id that will be fetched again from Firestore and will substitute the current entry on the static query.
That helps to avoid an enteire refresh of the query, saving document reads and fetching a single document instead of a list.
When you have a defined page size, this action get the previous set of documents of the query.
This event is triggered when the data from the query is ready, or when new data arrives in a dynamic query.
Each document updated in a dynamic query accounts trigges the event, so if you have, for instance, 3 quick updates, the event will be triggeres 3 times.
Keep in mind that, bacause the query operations run on the front-end, Bubble sometimes messes with the order in which data arrives from Firestore. That means you must account that factor while using results of other Firebase elements as input data in other query elements.
For instance, if you want to get documents form the "tasks" collection where the "owner" filter equals the current user's document reference, you can use the filter bellow (owner == users/Firebase Auth's User ID).
But if the User ID is not yet available, the query will fail due to security rules on Firestore.
To work around that, you can put a visibility conditional on the Firestore Data element, for it to show only when the User ID is not empty. As the query will only occur when the element is "visible" on the page, it will wait for when the User ID is available to run the query, avoiding the error.
Keep that in mind when fetching data from Firestore.
Count queries won't be dynamically updated. You'll have to run the action to update the count state.
You can read more on the .
Firestore does not offer "text" filters like the Bubble "contains keywords" option, because of the way they structure the database using indexes. For this kind os searches they recomend the use of external services like .
To sort data, you must specify the name of the field, it's type and the direction (descending = yes | ascending = no). In most cases, you'll want to make the sort field be the same from the .
The document JSON string, that can be provided to a to get the values from the document fields.
A list of document JSON strings, that can be provided to repeating groups and then, on each cell, extracted through a to get the values from the document fields.
When you have a defined page size, this action queries the next set of documents of the query, according to the page size you set, displaying them on the .
This won't make another query. Since the document were already available on the front-end, the plugin stores them to display them again as needed. If you which to update any entry on the document list already fetched, you can use the action.