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

This document describes how you can get AI-powered
assistance in Cloud Firestore to generate
MongoDB-compatible Query Language (MQL) queries using natural language
prompts.

Learn [how and when Gemini
for Google Cloud uses your data](https://docs.cloud.google.com/gemini/docs/discover/data-governance).

## Before you begin

1. Optional: [Set up Gemini Code Assist](https://docs.cloud.google.com//gemini/docs/discover/set-up-gemini).

2. To complete the tasks in this document, ensure that you have the
   [necessary Identity and Access Management (IAM) permissions](https://firebase.google.com/docs/firestore/enterprise/write-mql-gemini.md.txt#required-roles).

### Required roles

To get the permissions that you need to complete the tasks in this document, ask your administrator to grant you the [Gemini for Google Cloud User](https://docs.cloud.google.com/iam/docs/roles-permissions/cloudaicompanion#cloudaicompanion.user) (`roles/cloudaicompanion.user`) IAM role on the project.

## Generate MQL queries using natural language prompts

> [!CAUTION]
> As an early-stage technology, Gemini for Google Cloud
> products can generate output that seems plausible but is factually incorrect. We recommend that you
> validate all output from Gemini for Google Cloud products before you use it.
> For more information, see
> [Gemini for Google Cloud and responsible AI](https://docs.cloud.google.com//gemini/docs/discover/responsible-ai).

You can give Gemini natural language comments (or *prompts* ) to
generate queries that are based on your schema. For example, you can prompt
Gemini to generate MQL in response to the following prompts:

- "How many popular books with publication year 1960?"
- "Create a sample collection of popular books."

> [!NOTE]
> **Note:** When you enter a prompt for Gemini in Cloud Firestore, the database runs a `$sample` operation to retrieve 10 random documents to provide information about the database schema. You are charged for the read units for this operation.

To generate MQL in Cloud Firestore with Gemini
assistance, follow these steps:

1. In the Google Cloud console, go to the Cloud Firestore **Databases** page.

   [Go to Databases](https://console.cloud.google.com/firestore/databases)
2. Select an Cloud Firestore database from the list. The **Firestore Studio** opens.

3. In a new or empty query editor, click the **Generate MQL** button. Otherwise,
   click **Help me code**.

4. Enter a prompt to use to generate a query. To improve accuracy,
   select a collection for context in the drop-down.

5. Review the generated MQL and take any of the following actions:

   - To accept MQL generated by Gemini, click **Insert** . You can continue to edit the MQL in the editor. Click **Run** to run you query.
   - To edit your prompt, click **Edit**.

## What's next

- Read [Gemini for Google Cloud overview](https://docs.cloud.google.com//gemini/docs/overview).
- Learn [how Gemini uses your
  data](https://docs.cloud.google.com//gemini/docs/discover/data-governance).