> Documentation index: https://firebase.google.com/docs/firestore/llms.txt

> [!WARNING]
>
> **Preview**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://firebase.google.com/terms/service-terms#1).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).

To reuse and share common database operations across sessions, you can create,
organize, and manage saved
queries in
the Firebase console
.
For more information, see
[Saved queries overview](https://firebase.google.com/docs/firestore/enterprise/saved-queries.md.txt)
.

The saved queries capability is available only in the console, and not using APIs.

## Required roles

To get the permissions that you need to use saved queries, ask your
administrator to grant you the following Identity and Access Management (IAM) roles on
the project:

- To view saved queries: [Cloud Datastore Viewer](https://firebase.google.com/docs/firestore/enterprise/security/iam.md.txt#predefined_roles) (`roles/datastore.viewer`)
- To view, create, modify, and delete saved queries: [Cloud Datastore User](https://firebase.google.com/docs/firestore/enterprise/security/iam.md.txt#predefined_roles) (`roles/datastore.user`)
- To administer, view, create, modify, and delete saved queries: [Cloud Datastore Owner](https://firebase.google.com/docs/firestore/enterprise/security/iam.md.txt#predefined_roles) (`roles/datastore.owner`). This role has broad permissions and provides full access to Cloud Firestore, only for use by administrators.

For more information about granting roles, see [Manage access to projects, folders, and organizations](https://docs.cloud.google.com/iam/docs/granting-changing-revoking-access).

These predefined roles contain the permissions required to use saved
queries. To learn more about required permissions, see [Required permissions](https://firebase.google.com/docs/firestore/enterprise/create-manage-saved-queries.md.txt#required-permissions).

### Required permissions

To create, view, modify, and delete saved queries, you need the following IAM
permissions at the project level:

| **Action** | **Required IAM permissions** |
|---|---|
| Create saved queries | - `databasesconsole.studioQueries.create` |
| View saved queries | - `databasesconsole.studioQueries.search` - `databasesconsole.locations.get` - `databasesconsole.locations.list` |
| Modify saved queries | - `databasesconsole.studioQueries.update` |
| Delete saved queries | - `databasesconsole.studioQueries.delete` |
| Administer saved queries (Only for use by administrators) | - `databasesConsole.studioQueries.list` <!-- --> - `databasesconsole.locations.list` |

> [!NOTE]
> **Note:** Having access to saved queries doesn't automatically mean that you have permissions to run the query.

You can also get these permissions using [custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles)
or other [predefined roles](https://docs.cloud.google.com/iam/docs/roles-overview#predefined).

The [Studio Query User](https://docs.cloud.google.com/iam/docs/roles-permissions/databasesconsole)
(`roles/databasesconsole.studioQueryUser`)
role provides create, view, and write saved queries access. This role meets
the needs of most users.

Grant the [Studio Query Admin](https://docs.cloud.google.com/iam/docs/roles-permissions/databasesconsole)
(`roles/databasesconsole.studioQueryAdmin`)
role only to administrators. For more information about
Cloud Firestore IAM, see [Identity and Access Management](https://firebase.google.com/docs/firestore/enterprise/security/iam.md.txt#predefined_roles)
.

## Create a saved query

To create a saved query, follow these steps:

1. Go to the **Cloud Firestore** page in the Firebase console.  
   [Cloud Firestore](https://console.firebase.google.com/project/_/firestore/databases?useAutoProject=true)
2. Select a database in which you want to create a saved query. The database must be an Enterprise edition instance.
3. Click the **Query editor** tab.
4. In the query editor, enter a query.
5. Click **Save**.
6. In the **Save query** dialog, enter a name for the saved query.
7. Click **Save**.

## Open and run a saved query

To open a saved query as a new query, follow these steps:

1. In the **Query editor** , click **Saved queries** ().
2. Click a saved query to open it in a new editor tab. Optionally, you can click **View actions** next to a saved query. Then, click **Open query** to open it in a new editor tab.
3. Click **Run**.

## Update a saved query

To update an existing saved query, follow these steps:

1. In the **Query editor** , click **Saved queries** ().
2. Click a saved query to open it in a new editor tab. Optionally, you can click **View actions** next to a saved query. Then, click **Open query** to open it in a new editor tab.
3. Modify the query.
4. To save the modified query, click **Save**.

## View and manage a list of all saved queries

To view a list of all saved queries in your project, follow these steps:

In the Google Cloud console, go to the **Saved queries** page.
[Go to Saved queries](https://console.cloud.google.com/databases/queries?project=_)

You can search, filter, view, and delete queries on the **Saved queries**
page. You can't edit an existing query on the **Saved queries** page.

## Delete a saved query

You can delete a saved query from the **Cloud Firestore Studio**
page or on the **Saved queries** page in the Google Cloud console.

1. In the **Query editor** , click **Saved queries** ().
2. Click **View actions** next to the saved query that you want to delete. Then, to delete the saved query, click **Delete query**.
3. In the **Delete query** dialog, click **Delete**.

You can also delete a saved query on the **Saved queries** page. To delete a saved query on
the **Saved queries** page, follow these steps:

1. Navigate to the [**Saved queries**](https://firebase.google.com/docs/firestore/enterprise/create-manage-saved-queries.md.txt#view-and-manage) page.
2. Click **View actions** next to the saved query that you want to delete.
3. Click **Delete query** to delete the saved query.
4. In the **Delete query** dialog, click **Delete**.

## What's next

- Learn about [saved queries](https://firebase.google.com/docs/firestore/enterprise/saved-queries.md.txt).