Write MQL with Gemini assistance
This document describes how you can use Gemini Code Assist to get AI-powered assistance in Firestore to generate MQL queries using natural language prompts.
Learn how and when Gemini for Google Cloud uses your data.
Before you begin
Optional: Set up Gemini Code Assist.
To complete the tasks in this document, ensure that you have the necessary Identity and Access Management (IAM) permissions.
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 (roles/cloudaicompanion.user)
IAM role on the project.
For more information about granting roles, see Manage access to projects, folders, and organizations.
You might also be able to get the required permissions through custom roles or other predefined roles.
Generate MQL queries using natural language prompts
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."
To generate MQL in Firestore with Gemini assistance, follow these steps:
In the Google Cloud console, go to the Firestore Databases page.
Select an Firestore with MongoDB compatibility database from the list. The Firestore Studio opens.
In a new or empty query editor, click the Generate MQL button. Otherwise, click Help me code.
Enter a prompt to use to generate a query. To improve accuracy, select a collection for context in the drop-down.
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.