docs/en/integrations/firestore/tools/firestore-add-documents.md
The firestore-add-documents tool allows you to add new documents to a
Firestore collection. It supports all Firestore data types using Firestore's
native JSON format. The tool automatically generates a unique document ID for
each new document.
{{< compatible-sources >}}
| Parameter | Type | Required | Description |
|---|---|---|---|
collectionPath | string | Yes | The path of the collection where the document will be added |
documentData | map | Yes | The data to be added as a document to the given collection. Must use Firestore's native JSON format with typed values |
returnData | boolean | No | If set to true, the output will include the data of the created document. Defaults to false to help avoid overloading the context |
The tool requires Firestore's native JSON format for document data. Each field must be wrapped with its type indicator:
{"stringValue": "your string"}{"integerValue": "123"} or {"integerValue": 123}{"doubleValue": 123.45}{"booleanValue": true}{"nullValue": null}{"bytesValue": "base64EncodedString"}{"timestampValue": "2025-01-07T10:00:00Z"} (RFC3339 format){"geoPointValue": {"latitude": 34.052235, "longitude": -118.243683}}{"arrayValue": {"values": [{"stringValue": "item1"}, {"integerValue": "2"}]}}{"mapValue": {"fields": {"key1": {"stringValue": "value1"}, "key2": {"booleanValue": true}}}}{"referenceValue": "collection/document"}kind: tool
name: add-company-doc
type: firestore-add-documents
source: my-firestore
description: Add a new company document
Usage:
{
"collectionPath": "companies",
"documentData": {
"name": {
"stringValue": "Acme Corporation"
},
"establishmentDate": {
"timestampValue": "2000-01-15T10:30:00Z"
},
"location": {
"geoPointValue": {
"latitude": 34.052235,
"longitude": -118.243683
}
},
"active": {
"booleanValue": true
},
"employeeCount": {
"integerValue": "1500"
},
"annualRevenue": {
"doubleValue": 1234567.89
}
}
}
{
"collectionPath": "companies",
"documentData": {
"name": {
"stringValue": "Tech Innovations Inc"
},
"contactInfo": {
"mapValue": {
"fields": {
"email": {
"stringValue": "[email protected]"
},
"phone": {
"stringValue": "+1-555-123-4567"
},
"address": {
"mapValue": {
"fields": {
"street": {
"stringValue": "123 Innovation Drive"
},
"city": {
"stringValue": "San Francisco"
},
"state": {
"stringValue": "CA"
},
"zipCode": {
"stringValue": "94105"
}
}
}
}
}
}
},
"products": {
"arrayValue": {
"values": [
{
"stringValue": "Product A"
},
{
"stringValue": "Product B"
},
{
"mapValue": {
"fields": {
"productName": {
"stringValue": "Product C Premium"
},
"version": {
"integerValue": "3"
},
"features": {
"arrayValue": {
"values": [
{
"stringValue": "Advanced Analytics"
},
{
"stringValue": "Real-time Sync"
}
]
}
}
}
}
}
]
}
}
},
"returnData": true
}
{
"collectionPath": "test-documents",
"documentData": {
"stringField": {
"stringValue": "Hello World"
},
"integerField": {
"integerValue": "42"
},
"doubleField": {
"doubleValue": 3.14159
},
"booleanField": {
"booleanValue": true
},
"nullField": {
"nullValue": null
},
"timestampField": {
"timestampValue": "2025-01-07T15:30:00Z"
},
"geoPointField": {
"geoPointValue": {
"latitude": 37.7749,
"longitude": -122.4194
}
},
"bytesField": {
"bytesValue": "SGVsbG8gV29ybGQh"
},
"arrayField": {
"arrayValue": {
"values": [
{
"stringValue": "item1"
},
{
"integerValue": "2"
},
{
"booleanValue": false
}
]
}
},
"mapField": {
"mapValue": {
"fields": {
"nestedString": {
"stringValue": "nested value"
},
"nestedNumber": {
"doubleValue": 99.99
}
}
}
}
}
}
The tool returns a map containing:
| Field | Type | Description |
|---|---|---|
documentPath | string | The full resource name of the created document (e.g., projects/{projectId}/databases/{databaseId}/documents/{document_path}) |
createTime | string | The timestamp when the document was created |
documentData | map | The data that was added (only included when returnData is true) |
The tool can be configured to require authentication:
kind: tool
name: secure-add-docs
type: firestore-add-documents
source: prod-firestore
description: Add documents with authentication required
authRequired:
- google-oauth
- api-key
{"stringValue": "text"}){"integerValue": "1500"})bytesValue fieldCommon errors include:
firestore-get-documents - Retrieve documents
by their pathsfirestore-query-collection - Query
documents in a collectionfirestore-delete-documents - Delete
documents from Firestore