# Firebase Query

The Firebase Query action allows you to execute multiple operations in *Firestore*, *Realtime DB*, and *Firebase Auth* services. In order to to execute the query you need to select the service, method, and define their parameters.\
You can use UI Bakery variables to compose keys in Realtime DB, collection names in Firestore queries, and so on.&#x20;

Below you'll find more Firebase Query examples for all the services.

## Working with Firestore

### Getting collections list

To get a list of your collections, you need to select your *Firestore* data source from the list of data sources and select the **Firebase Query** action type. \
Choose **Get collection list** as the *Firestore method* and provide the **Parent document ID** or leave it blank for top level collections.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FoCFLqz0NKpQMI7ZjjWsq%2FCleanShot%202025-04-15%20at%2011.31.07%402x-min.png?alt=media&#x26;token=18eb240c-2e09-46f7-8cba-cb7a43502e32" alt=""><figcaption></figcaption></figure>

### Querying Firestore

To query Firestore, you need to select your *Firestore* data source from the list of data sources and select the **Firebase Query** action type.  \
Choose **Query** as the *Firestore method* and specify your collection name. You can filter your query by values, add limits, and add ordering by a certain field.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FjHCMIikyENkD8qWZ4YlC%2FCleanShot%202025-04-15%20at%2011.35.31%402x-min.png?alt=media&#x26;token=77eb131b-5aed-4cdd-bfe6-208481471f36" alt=""><figcaption></figcaption></figure>

### Getting a document by ID

To get a document by ID, you need to select your *Firestore* data source from the list of data sources and select the **Firebase Query** action type. \
Choose **Get document by ID** as the *Firestore method* and specify the collection name and document ID. Document ID can receive dynamic values passed in `{{}}`.

### Updating a document

To update a document, you need to select your *Firestore* data source from the list of data sources and select the **Firebase Query** action type.  \
Choose **Update document** as the *Firestore method*. Specify the collection name, document ID and the objects that need to be updated. Document ID and values can receive dynamic values passed in `{{}}`.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FlQl0WIWZfBWAFGo1I9ga%2FCleanShot%202025-04-15%20at%2011.42.36%402x-min.png?alt=media&#x26;token=7ff435b9-1884-4ae5-9c46-46ce11ee33ff" alt=""><figcaption></figcaption></figure>

### Inserting a document

To insert a document, you need to select your *Firestore* data source from the list of data sources and select the **Firebase Query** action type. \
Choose **Insert document** as the *Firestore method*. Since the pattern of document insert is the same as for updating a document, you can leave the document ID blank, and Firestore will generate it automatically.

### Deleting a document

To delete a document, you need to select your *Firestore* data source from the list of data sources and select the **Firebase Query** action type.\
Choose **Delete document** as the *Firestore method* and only provide the document ID. Document ID can receive dynamic values passed in `{{}}`.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FXWf2j64wVhPPL304oDYn%2FCleanShot%202025-04-15%20at%2011.46.29%402x-min.png?alt=media&#x26;token=971d0e63-c02b-488c-bfca-43d58e052fd2" alt=""><figcaption></figcaption></figure>

### Querying collection group

To query a collection group, you need to select your *Firestore* data source from the list of data sources and select the **Firebase Query** action type.  \
Choose **Query collection group** as the *Firestore method* and specify your collection name. You can filter your query by values, add limits, and add ordering by a certain field.

## Working with Firebase Auth

With UI Bakery, you can manage your users from the Firebase Auth setup, namely view, update, create new and delete existing users.

### Listing users

To get a list of your users, you need to select your *Firestore Auth* data source from the list of data sources and select the **Firebase Query** action type.\
Choose **List users** as the *Firebase Auth method*. You can limit the number of returned users if necessary.

### Getting user by UID/ email/ phone number

To get a certain user by their UID, phone number or email, you need to select your *Firestore Auth* data source from the list of data sources and select the **Firebase Query** action type.\
Choose **Get user by UID/ email/ phone number** as the *Firebase Auth method*.

### Creating a new user

To create a new user, you need to select your *Firestore Auth* data source from the list of data sources and select the **Firebase Query** action type. \
Choose **Create user** as the *Firebase Auth method* and provide a user object.

### Updating a user

To update user's information, you need to select your *Firestore Auth* data source from the list of data sources and select the **Firebase Query** action type. \
Choose **Update user** as the *Firebase Auth method* and specify user's UID and the update object.

### Deleting a user

To delete a user, you need to select your *Firestore Auth* data source from the list of data sources and select the **Firebase Query** action type. \
Choose **Delete user** as the *Firebase Auth method* and specify user's UID.

## Working with Realtime DB

### Querying the database

To query Realtime DB, you need to select your *RealtimeDB* data source from the list of data sources and select the **Firebase Query** action type. \
Choose **Query** as the *Realtime database method* and specify your [database reference](https://firebase.google.com/docs/reference/js/database.databasereference.md).

To enable additional filtering options, turn on the **Use ordering** toggle. The following filters are available:

* Ordering by child, key, value, or priority
* Ordering by limit (limit to first/ limit to last)
* Filtering queries with `equalTo`, `startAt`, `endAt`

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FtxL600GL3jCM7oY2dXhT%2FCleanShot%202025-04-15%20at%2012.23.32%402x-min.png?alt=media&#x26;token=ea43ccd3-3756-43bb-a11d-2da359dd0016" alt=""><figcaption></figcaption></figure>

### Setting/updating data

In Firebase databases, you can use two approaches to updating data:

* `set` rewrites the current values of an item
* `update` updates the required values of an item, but doesn't rewrite all the values of an object

To use the `set` method, select it from the action dropdown, specify the database ref and the data object.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FYYOla1LW7oPIE8UY46na%2FCleanShot%202025-04-15%20at%2012.47.03%402x-min.png?alt=media&#x26;token=d71fa486-61e9-40de-8234-fb94b0d941e3" alt=""><figcaption></figcaption></figure>

To use the `update` method, select it from the dropdown, specify the database ref and the data object.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2FC8VXdLdWBitKJ7OvVIUi%2FCleanShot%202025-04-15%20at%2012.48.59%402x-min.png?alt=media&#x26;token=220b948d-fde5-41d9-8194-02e2eceb4bb9" alt=""><figcaption></figcaption></figure>

### Appending data to a list

To append data to a list, you need to select your *RealtimeDB* data source from the list of data sources and select the **Firebase Query** action type. \
Choose **Append data to a list** as the *Realtime database method* and specify your database ref and the data object.

<figure><img src="https://837703843-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FUX6zPRMFFK0yrTghj7cY%2Fuploads%2Fyge0td1yBsi0RyACnlMJ%2FCleanShot%202025-04-30%20at%2016.40.12%402x-min.png?alt=media&#x26;token=336997b0-764d-4fae-b0ac-30d1b68490df" alt=""><figcaption></figcaption></figure>
