适用于 Firestore 的连接器

定义用于在工作流内访问 Firestore 的内置函数的 Workflows 连接器。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

YAML

# This workflow demonstrates how to use the Firestore connector.
# The workflow first creates a Firestore document, then retrieves the document,
# and exports the document to a Google Cloud Storage bucket.
# The document is deleted eventually.
# Expected successful 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"  # Make sure this bucket exists.
        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"

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器