docs/en/integrations/firestore/tools/firestore-query-collection.md
The firestore-query-collection tool allows you to query Firestore collections
with filters, ordering, and limit capabilities.
{{< compatible-sources >}}
| parameters | type | required | default | description |
|---|---|---|---|---|
collectionPath | string | true | - | The Firestore Rules source code to validate |
filters | array | false | - | Array of filter objects (as JSON strings) to apply to the query |
orderBy | string | false | - | JSON string specifying field and direction to order results |
limit | integer | false | 100 | Maximum number of documents to return |
analyzeQuery | boolean | false | false | If true, returns query explain metrics including execution statistics |
To use this tool, you need to configure it in your YAML configuration file:
kind: source
name: my-firestore
type: firestore
project: my-gcp-project
database: "(default)"
---
kind: tool
name: query_collection
type: firestore-query-collection
source: my-firestore
description: Query Firestore collections with advanced filtering
Each filter in the filters array should be a JSON string with the following
structure:
{
"field": "fieldName",
"op": "operator",
"value": "compareValue"
}
Supported operators:
< - Less than<= - Less than or equal to> - Greater than>= - Greater than or equal to== - Equal to!= - Not equal toarray-contains - Array contains a specific valuearray-contains-any - Array contains any of the specified valuesin - Field value is in the specified arraynot-in - Field value is not in the specified arrayValue types supported:
"value": "text""value": 123 or "value": 45.67"value": true or "value": false"value": ["item1", "item2"] (for in, not-in, array-contains-any
operators)The orderBy parameter should be a JSON string with the following structure:
{
"field": "fieldName",
"direction": "ASCENDING"
}
Direction values:
ASCENDINGDESCENDING{
"collectionPath": "users",
"filters": [
"{\"field\": \"age\", \"op\": \">\", \"value\": 18}",
"{\"field\": \"status\", \"op\": \"==\", \"value\": \"active\"}"
],
"orderBy": "{\"field\": \"createdAt\", \"direction\": \"DESCENDING\"}",
"limit": 50
}
{
"collectionPath": "products",
"filters": [
"{\"field\": \"categories\", \"op\": \"array-contains\", \"value\": \"electronics\"}",
"{\"field\": \"price\", \"op\": \"<\", \"value\": 1000}"
],
"orderBy": "{\"field\": \"price\", \"direction\": \"ASCENDING\"}",
"limit": 20
}
{
"collectionPath": "orders",
"filters": [
"{\"field\": \"status\", \"op\": \"in\", \"value\": [\"pending\", \"processing\"]}"
],
"limit": 100
}
{
"collectionPath": "users",
"filters": [
"{\"field\": \"age\", \"op\": \">=\", \"value\": 21}",
"{\"field\": \"active\", \"op\": \"==\", \"value\": true}"
],
"orderBy": "{\"field\": \"lastLogin\", \"direction\": \"DESCENDING\"}",
"limit": 25,
"analyzeQuery": true
}
The tool returns an array of documents, where each document includes:
{
"id": "documentId",
"path": "collection/documentId",
"data": {
// Document fields
},
"createTime": "2025-01-07T12:00:00Z",
"updateTime": "2025-01-07T12:00:00Z",
"readTime": "2025-01-07T12:00:00Z"
}
When analyzeQuery is set to true, the tool returns a single object containing
documents and explain metrics:
{
"documents": [
// Array of document objects as shown above
],
"explainMetrics": {
"planSummary": {
"indexesUsed": [
{
"query_scope": "Collection",
"properties": "(field ASC, __name__ ASC)"
}
]
},
"executionStats": {
"resultsReturned": 50,
"readOperations": 50,
"executionDuration": "120ms",
"debugStats": {
"indexes_entries_scanned": "1000",
"documents_scanned": "50",
"billing_details": {
"documents_billable": "50",
"index_entries_billable": "1000",
"min_query_cost": "0"
}
}
}
}
}
The tool will return errors for: