Firestore용 커넥터

워크플로 내에서 Firestore에 액세스하는 데 사용되는 기본 제공 함수를 정의하는 Workflows 커넥터입니다.

더 살펴보기

이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.

코드 샘플

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"

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.