Firebase Auth, Firestore & Storage (plugin)
  • 🚀Getting Started
  • Setup
    • Create a Firebase Project
    • Get Firebase access credentials
    • Offline Support
    • Secure your credentials and data
      • Restrict your api-key to your domain
      • Security Rules on Firebase
  • Plugin Elements
    • 🛠️About elements
    • 💾Data Schemas
    • Firebase Auth (Current User)
    • Firestore Data List
      • Firebase Geohash
      • Firestore Data (legacy)
    • Firestore Data Extractor
    • Firestore Data Single
    • Firestore Data Aggregation
    • Firestore Data Processor
    • Firebase Storage Upload Button
    • Firebase Action Listener
    • Firebase Dropdown Processor
  • Plugin Front-end Actions
    • 💻About front-end actions
    • 💾Field types table
    • Firestore
      • Create a new document
      • Update a document
      • Delete a document
      • Update a list of documents
      • Delete a list of documents
      • Batch Operations
        • Batch Operation Constructor
        • Batch Operation Commit
    • Firebase Auth
      • Sign the User Up
      • Log the User In
      • Log the User In with Google
      • Log the User In with Facebook
      • Log the User In with GitHub
      • Log the User Out
      • Update User's Profile
      • Update User's Password
      • Update User's Email
      • Send password reset email
        • Handle reset password code
      • Send verification email
        • Handle verify email code
      • Delete current user
    • Firebase Storage
      • Upload file base64
      • Delete uploaded file
  • Plugin Back-end Actions
    • ☁️About backend actions
    • Firestore Backend
      • Get a list of documents
      • Get a single document
      • Count a list of documents
      • Create a new document
      • Update a document
      • Delete a document
      • Update a list of documents
      • Delete a list of documents
    • Firebase Auth Backend
      • Create an account for someone else
      • Update another user's profile info
      • Delete a user account
      • Generate email confirmation link
      • Generate password reset link
      • Set user roles
Powered by GitBook
On this page
  • Settings
  • Firestore Collection
  • Aggregation Type
  • Field
  • Query sort / order by options (list)
  • Query filters (list) (count)
  • States and Values
  • Result
  • Collection
  • Error message
  • Element Actions
  • Refresh (list)
  • Events
  • Data ready or changed
  • Using query results as inputs in other queries
  1. Plugin Elements

Firestore Data Aggregation

PreviousFirestore Data SingleNextFirestore Data Processor

Last updated 1 year ago

The Firestore Data Aggregation allows you calculate averages, sums or count documents at query level, which can be useful to aggregate information without the need to "read" all documents, saving document reads and reducing the amount of data broght to the front-end.


Settings

Firestore Collection

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. 🙂

Aggregation Type

  • 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)

  • Average Calculates the average value of a field you specify for the list of documents being queried. If the field is not quantifiable, the query will result in a error.

  • Sum Calculates the sum of a field you specify for the list of documents being queried. If the field is not quantifiable, the query will result in a error.

Field

The field of the list of documents you with to aggregate.

Will be ignored for "count" aggregations.

Query sort / order by options (list)

You can choose a field to order your list of document from, at query level, specifying the sort direction (descending = yes | ascending = no).

Query filters (list) (count)

This options allow you to choose fields from which to filter your query.

You can choose to ignore empty constraints, which will simple "skip" the filter if the input you provided is empty.

Available query operators

Operator
Description

<

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.

Types of filter values

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:

Type
How it will be handled

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"

Arrays and lists are always handled in JavaScript notation, which means each value should be comma separated and must be between brackets.

An array of number should be provided as a text like: [1, 3, 45, 2]

An array of texts should contain balues between quotes: ["text1", "text2", "text3"]

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"


States and Values

Result

The result of the aggregation query, always a number, that can be a count, average or sum.

Collection

The name of the collection from which the element is getting it's data from.

Error message

If the query fails and returns an error, the error message will be stored on this state.


Element Actions

Refresh (list)

This action reloads the elements data, performing the query again. This might be useful to provide consistency in your data, since the aggregation query can't be dynamic.


Events

Data ready or changed

This event is triggered when the query data is ready.


Using query results as inputs in other queries

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.

This can affect the result, as sorting can behave as a filter in queries if the sorting field is not present in a document. You should use this setting to reproduce the exact settings of a element you want to count document from, for instance.

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 .

Firestore Data
Cloud Firestore documentation
Algolia
Query filter operators
Query filter value types