Cloud Firestore API Connector Overview

The Workflows connector defines the built-in functions that can be used to access other Google Cloud products within a workflow.

This page provides an overview of the individual connector. There is no need to import or load connector libraries in a workflow—connectors work out of the box when used in a call step.

Cloud Firestore API

Accesses the NoSQL document database built for automatic scaling, high performance, and ease of application development. To learn more, see the Cloud Firestore API documentation.

The Firestore connector allows you to connect to the Firestore APIs from within a workflow.

The Firestore connector only supports databases created in Native mode. Operations will fail if used on a database in Datastore mode. To learn more about the difference between the two, see Choosing between Native mode and Datastore mode.

Cloud Firestore connector sample

YAML

# This workflow demonstrates how to use the Firestore connector:
# Create and retrieve a Firestore document
# Export the document to a Cloud Storage bucket (which must already exist)
# Delete the document
# Expected output: "SUCCESS"
- init:
    assign:
      - project_id: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
      - collection: "example-collection"
      - document: "example-document"
- create_document:
    call: googleapis.firestore.v1.projects.databases.documents.createDocument
    args:
      collectionId: ${collection}
      parent: ${"projects/" + project_id + "/databases/(default)/documents"}
      query:
        documentId: ${document}
      body:
        fields:
          fieldA:
            stringValue: abc
          fieldB:
            integerValue: 123
- get_document:
    call: googleapis.firestore.v1.projects.databases.documents.get
    args:
      name: ${"projects/" + project_id + "/databases/(default)/documents/" + collection + "/" + document}
    result: got
- check:
    switch:
      - condition: ${got.fields.fieldA.stringValue == "abc" AND int(got.fields.fieldB.integerValue) == 123}
        next: export
- failed:
    raise: ${"got unexpected document" + "fieldA:" + got.fields.fieldA.stringValue + " fieldB:" + string(got.fields.fieldB.integerValue)}
- export:
    call: googleapis.firestore.v1.projects.databases.exportDocuments
    args:
      name: ${"projects/" + project_id + "/databases/(default)"}
      body:
        outputUriPrefix: "gs://EXAMPLE_BUCKET"  # replace EXAMPLE_BUCKET placeholder with existing bucket
        collectionIds:
          - ${collection}
- drop:
    call: googleapis.firestore.v1.projects.databases.documents.delete
    args:
      name: ${"projects/" + project_id + "/databases/(default)/documents/" + collection + "/" + document}
- the_end:
    return: "SUCCESS"

JSON

[
  {
    "init": {
      "assign": [
        {
          "project_id": "${sys.get_env(\"GOOGLE_CLOUD_PROJECT_ID\")}"
        },
        {
          "collection": "example-collection"
        },
        {
          "document": "example-document"
        }
      ]
    }
  },
  {
    "create_document": {
      "call": "googleapis.firestore.v1.projects.databases.documents.createDocument",
      "args": {
        "collectionId": "${collection}",
        "parent": "${\"projects/\" + project_id + \"/databases/(default)/documents\"}",
        "query": {
          "documentId": "${document}"
        },
        "body": {
          "fields": {
            "fieldA": {
              "stringValue": "abc"
            },
            "fieldB": {
              "integerValue": 123
            }
          }
        }
      }
    }
  },
  {
    "get_document": {
      "call": "googleapis.firestore.v1.projects.databases.documents.get",
      "args": {
        "name": "${\"projects/\" + project_id + \"/databases/(default)/documents/\" + collection + \"/\" + document}"
      },
      "result": "got"
    }
  },
  {
    "check": {
      "switch": [
        {
          "condition": "${got.fields.fieldA.stringValue == \"abc\" AND int(got.fields.fieldB.integerValue) == 123}",
          "next": "export"
        }
      ]
    }
  },
  {
    "failed": {
      "raise": "${\"got unexpected document\" + \"fieldA:\" + got.fields.fieldA.stringValue + \" fieldB:\" + string(got.fields.fieldB.integerValue)}"
    }
  },
  {
    "export": {
      "call": "googleapis.firestore.v1.projects.databases.exportDocuments",
      "args": {
        "name": "${\"projects/\" + project_id + \"/databases/(default)\"}",
        "body": {
          "outputUriPrefix": "gs://EXAMPLE_BUCKET",
          "collectionIds": [
            "${collection}"
          ]
        }
      }
    }
  },
  {
    "drop": {
      "call": "googleapis.firestore.v1.projects.databases.documents.delete",
      "args": {
        "name": "${\"projects/\" + project_id + \"/databases/(default)/documents/\" + collection + \"/\" + document}"
      }
    }
  },
  {
    "the_end": {
      "return": "SUCCESS"
    }
  }
]

Module: googleapis.firestore.v1.projects.databases

Functions
exportDocuments Exports a copy of all or a subset of documents from Google Cloud Firestore to another storage system, such as Google Cloud Storage. Recent updates to documents may not be reflected in the export. The export occurs in the background and its progress can be monitored and managed via the Operation resource that is created. The output of an export may only be used once the associated operation is done. If an export operation is cancelled before completion it may leave partial data behind in Google Cloud Storage. For more details on export behavior and output format, refer to: https://cloud.google.com/firestore/docs/manage-data/export-import
importDocuments Imports documents into Google Cloud Firestore. Existing documents with the same name are overwritten. The import occurs in the background and its progress can be monitored and managed via the Operation resource that is created. If an ImportDocuments operation is cancelled, it is possible that a subset of the data has already been imported to Cloud Firestore.

Module: googleapis.firestore.v1.projects.databases.collectionGroups.fields

Functions
get Gets the metadata and configuration for a Field.
list Lists the field configuration and metadata for this database. Currently, FirestoreAdmin.ListFields only supports listing fields that have been explicitly overridden. To issue this query, call FirestoreAdmin.ListFields with the filter set to indexConfig.usesAncestorConfig:false .
patch Updates a field configuration. Currently, field updates apply only to single field index configuration. However, calls to FirestoreAdmin.UpdateField should provide a field mask to avoid changing any configuration that the caller isn't aware of. The field mask should be specified as: { paths: "index_config" }. This call returns a google.longrunning.Operation which may be used to track the status of the field update. The metadata for the operation will be the type FieldOperationMetadata. To configure the default field settings for the database, use the special Field with resource name: projects/{project_id}/databases/{database_id}/collectionGroups/__default__/fields/*.

Module: googleapis.firestore.v1.projects.databases.collectionGroups.indexes

Functions
create Creates a composite index. This returns a google.longrunning.Operation which may be used to track the status of the creation. The metadata for the operation will be the type IndexOperationMetadata.
delete Deletes a composite index.
get Gets a composite index.
list Lists composite indexes.

Module: googleapis.firestore.v1.projects.databases.documents

Functions
batchGet Gets multiple documents. Documents returned by this method are not guaranteed to be returned in the same order that they were requested.
batchWrite Applies a batch of write operations. The BatchWrite method does not apply the write operations atomically and can apply them out of order. Method does not allow more than one write per document. Each write succeeds or fails independently. See the BatchWriteResponse for the success status of each write. If you require an atomically applied set of writes, use Commit instead.
beginTransaction Starts a new transaction.
commit Commits a transaction, while optionally updating documents.
createDocument Creates a new document.
delete Deletes a document.
get Gets a single document.
list Lists documents.
listCollectionIds Lists all the collection IDs underneath a document.
partitionQuery Partitions a query by returning partition cursors that can be used to run the query in parallel. The returned partition cursors are split points that can be used by RunQuery as starting/end points for the query results.
patch Updates or inserts a document.
rollback Rolls back a transaction.
runQuery Runs a query.

Module: googleapis.firestore.v1.projects.databases.operations

Functions
cancel Starts asynchronous cancellation on a long-running operation. The server makes a best effort to cancel the operation, but success is not guaranteed. If the server doesn't support this method, it returns google.rpc.Code.UNIMPLEMENTED. Clients can use Operations.GetOperation or other methods to check whether the cancellation succeeded or whether the operation completed despite cancellation. On successful cancellation, the operation is not deleted; instead, it becomes an operation with an Operation.error value with a google.rpc.Status.code of 1, corresponding to Code.CANCELLED.
delete Deletes a long-running operation. This method indicates that the client is no longer interested in the operation result. It does not cancel the operation. If the server doesn't support this method, it returns google.rpc.Code.UNIMPLEMENTED.
get Gets the latest state of a long-running operation. Clients can use this method to poll the operation result at intervals as recommended by the API service.
list Lists operations that match the specified filter in the request. If the server doesn't support this method, it returns UNIMPLEMENTED. NOTE: the name binding allows API services to override the binding to use different resource name schemes, such as users/*/operations. To override the binding, API services can add a binding such as "/v1/{name=users/*}/operations" to their service configuration. For backwards compatibility, the default name includes the operations collection id, however overriding users must ensure the name binding is the parent resource, without the operations collection id.

Module: googleapis.firestore.v1.projects.locations

Functions
get Gets information about a location.
list Lists information about the supported locations for this service.

Module: googleapis.firestore.v1beta1.projects.databases

Functions
exportDocuments Exports a copy of all or a subset of documents from Google Cloud Firestore to another storage system, such as Google Cloud Storage. Recent updates to documents may not be reflected in the export. The export occurs in the background and its progress can be monitored and managed via the Operation resource that is created. The output of an export may only be used once the associated operation is done. If an export operation is cancelled before completion it may leave partial data behind in Google Cloud Storage.
importDocuments Imports documents into Google Cloud Firestore. Existing documents with the same name are overwritten. The import occurs in the background and its progress can be monitored and managed via the Operation resource that is created. If an ImportDocuments operation is cancelled, it is possible that a subset of the data has already been imported to Cloud Firestore.

Module: googleapis.firestore.v1beta1.projects.databases.documents

Functions
batchGet Gets multiple documents. Documents returned by this method are not guaranteed to be returned in the same order that they were requested.
batchWrite Applies a batch of write operations. The BatchWrite method does not apply the write operations atomically and can apply them out of order. Method does not allow more than one write per document. Each write succeeds or fails independently. See the BatchWriteResponse for the success status of each write. If you require an atomically applied set of writes, use Commit instead.
beginTransaction Starts a new transaction.
commit Commits a transaction, while optionally updating documents.
createDocument Creates a new document.
delete Deletes a document.
get Gets a single document.
list Lists documents.
listCollectionIds Lists all the collection IDs underneath a document.
partitionQuery Partitions a query by returning partition cursors that can be used to run the query in parallel. The returned partition cursors are split points that can be used by RunQuery as starting/end points for the query results.
patch Updates or inserts a document.
rollback Rolls back a transaction.
runQuery Runs a query.

Module: googleapis.firestore.v1beta1.projects.databases.indexes

Functions
create Creates the specified index. A newly created index's initial state is CREATING. On completion of the returned google.longrunning.Operation, the state will be READY. If the index already exists, the call will return an ALREADY_EXISTS status. During creation, the process could result in an error, in which case the index will move to the ERROR state. The process can be recovered by fixing the data that caused the error, removing the index with delete, then re-creating the index with create. Indexes with a single field cannot be created.
delete Deletes an index.
get Gets an index.
list Lists the indexes that match the specified filters.

Module: googleapis.firestore.v1beta2.projects.databases

Functions
exportDocuments Exports a copy of all or a subset of documents from Google Cloud Firestore to another storage system, such as Google Cloud Storage. Recent updates to documents may not be reflected in the export. The export occurs in the background and its progress can be monitored and managed via the Operation resource that is created. The output of an export may only be used once the associated operation is done. If an export operation is cancelled before completion it may leave partial data behind in Google Cloud Storage.
importDocuments Imports documents into Google Cloud Firestore. Existing documents with the same name are overwritten. The import occurs in the background and its progress can be monitored and managed via the Operation resource that is created. If an ImportDocuments operation is cancelled, it is possible that a subset of the data has already been imported to Cloud Firestore.

Module: googleapis.firestore.v1beta2.projects.databases.collectionGroups.fields

Functions
get Gets the metadata and configuration for a Field.
list Lists the field configuration and metadata for this database. Currently, FirestoreAdmin.ListFields only supports listing fields that have been explicitly overridden. To issue this query, call FirestoreAdmin.ListFields with the filter set to indexConfig.usesAncestorConfig:false.
patch Updates a field configuration. Currently, field updates apply only to single field index configuration. However, calls to FirestoreAdmin.UpdateField should provide a field mask to avoid changing any configuration that the caller isn't aware of. The field mask should be specified as: { paths: "index_config" }. This call returns a google.longrunning.Operation which may be used to track the status of the field update. The metadata for the operation will be the type FieldOperationMetadata. To configure the default field settings for the database, use the special Field with resource name: projects/{project_id}/databases/{database_id}/collectionGroups/__default__/fields/*.

Module: googleapis.firestore.v1beta2.projects.databases.collectionGroups.indexes

Functions
create Creates a composite index. This returns a google.longrunning.Operation which may be used to track the status of the creation. The metadata for the operation will be the type IndexOperationMetadata.
delete Deletes a composite index.
get Gets a composite index.
list Lists composite indexes.