ขยาย Cloud Firestore ด้วย Cloud Functions (รุ่นที่ 2)

คุณสามารถใช้ฟังก์ชันระบบคลาวด์เพื่อทำให้โค้ดใช้งานได้เพื่อจัดการกับเหตุการณ์ที่ทริกเกอร์ ด้วยการเปลี่ยนแปลงในฐานข้อมูล Cloud Firestore ซึ่งจะช่วยให้คุณเพิ่มฝั่งเซิร์ฟเวอร์ ฟังก์ชันที่มีอยู่ลงในแอปของคุณโดยไม่ต้องใช้เซิร์ฟเวอร์ของคุณเอง

Cloud Functions (รุ่นที่ 2)

ขับเคลื่อนโดย Cloud Run และ Eventarc Cloud Functions for Firebase (รุ่นที่ 2) มีประสิทธิภาพมากขึ้น การควบคุมขั้นสูงในด้านประสิทธิภาพและความสามารถในการปรับขนาด และอื่นๆ ควบคุมรันไทม์ของฟังก์ชัน ดูข้อมูลเพิ่มเติมเกี่ยวกับรุ่นที่ 2 ได้ที่ Cloud Functions for Firebase (รุ่นที่ 2) ดูเพิ่มเติม เกี่ยวกับรุ่นที่ 1 แทน โปรดดู ขยาย Cloud Firestore ด้วย Cloud Functions

ทริกเกอร์ฟังก์ชัน Cloud Firestore

Cloud Functions for Firebase SDK จะส่งออก Cloud Firestore ต่อไปนี้ ทริกเกอร์เหตุการณ์ที่จะช่วยให้คุณสร้างเครื่องจัดการที่ผูกกับ Cloud Firestore ที่เฉพาะเจาะจงได้ กิจกรรม:

Node.js

ประเภทเหตุการณ์ ทริกเกอร์
onDocumentCreated ทริกเกอร์เมื่อเขียนเอกสารถึงเป็นครั้งแรก
onDocumentUpdated ทริกเกอร์เมื่อมีเอกสารอยู่แล้วและมีการเปลี่ยนแปลงค่า
onDocumentDeleted ทริกเกอร์เมื่อลบเอกสาร
onDocumentWritten ทริกเกอร์เมื่อมีการทริกเกอร์ onDocumentCreated, onDocumentUpdated หรือ onDocumentDeleted
onDocumentCreatedWithAuthContext onDocumentCreated ที่มีข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม
onDocumentWrittenWithAuthContext onDocumentWritten ที่มีข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม
onDocumentDeletedWithAuthContext onDocumentDeleted ที่มีข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม
onDocumentUpdatedWithAuthContext onDocumentUpdated ที่มีข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม

Python (ตัวอย่าง)

ประเภทเหตุการณ์ ทริกเกอร์
on_document_created ทริกเกอร์เมื่อเขียนเอกสารถึงเป็นครั้งแรก
on_document_updated ทริกเกอร์เมื่อมีเอกสารอยู่แล้วและมีการเปลี่ยนแปลงค่า
on_document_deleted ทริกเกอร์เมื่อลบเอกสาร
on_document_written ทริกเกอร์เมื่อมีการทริกเกอร์ on_document_created, on_document_updated หรือ on_document_deleted
on_document_created_with_auth_context on_document_created ที่มีข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม
on_document_updated_with_auth_context on_document_updated ที่มีข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม
on_document_deleted_with_auth_context on_document_deleted ที่มีข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม
on_document_written_with_auth_context on_document_written ที่มีข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม

ทริกเกอร์เหตุการณ์ Cloud Firestore เท่านั้น เมื่อมีการเปลี่ยนแปลงในเอกสาร การอัปเดตเอกสาร Cloud Firestore ที่มีข้อมูล ไม่มีการเปลี่ยนแปลง (การเขียนที่ไม่มีการเปลี่ยนแปลง) จะไม่สร้างการอัปเดตหรือการเขียนเหตุการณ์ ใช่เลย ไม่สามารถเพิ่มเหตุการณ์ลงในฟิลด์บางฟิลด์ได้

หากคุณยังไม่เปิดใช้โปรเจ็กต์สำหรับฟังก์ชันระบบคลาวด์สำหรับ Firebase โปรดอ่าน เริ่มต้นใช้งาน Cloud Functions for Firebase (รุ่นที่ 2) เพื่อกำหนดค่าและตั้งค่า Cloud Functions for Firebase

การเขียนฟังก์ชันที่ทริกเกอร์ใน Cloud Firestore

กำหนดทริกเกอร์ฟังก์ชัน

หากต้องการกำหนดทริกเกอร์ Cloud Firestore ให้ระบุเส้นทางของเอกสารและประเภทเหตุการณ์ดังนี้

Node.js

import {
  onDocumentWritten,
  onDocumentCreated,
  onDocumentUpdated,
  onDocumentDeleted,
  Change,
  FirestoreEvent
} from "firebase-functions/v2/firestore";

exports.myfunction = onDocumentWritten("my-collection/{docId}", (event) => {
   /* ... */ 
});

Python (ตัวอย่าง)

from firebase_functions.firestore_fn import (
  on_document_created,
  on_document_deleted,
  on_document_updated,
  on_document_written,
  Event,
  Change,
  DocumentSnapshot,
)

@on_document_created(document="users/{userId}")
def myfunction(event: Event[DocumentSnapshot]) -> None:

เส้นทางเอกสารสามารถอ้างอิงเอกสารที่เฉพาะเจาะจงได้ หรือรูปแบบไวลด์การ์ด

ระบุเอกสารเดียว

หากคุณต้องการทริกเกอร์เหตุการณ์สำหรับการเปลี่ยนแปลงใดๆ ในเอกสารที่เจาะจง ให้ทำดังนี้ คุณสามารถใช้ฟังก์ชันต่อไปนี้

Node.js

import {
  onDocumentWritten,
  Change,
  FirestoreEvent
} from "firebase-functions/v2/firestore";

exports.myfunction = onDocumentWritten("users/marie", (event) => {
  // Your code here
});

Python (ตัวอย่าง)

from firebase_functions.firestore_fn import (
  on_document_written,
  Event,
  Change,
  DocumentSnapshot,
)

@on_document_written(document="users/marie")
def myfunction(event: Event[Change[DocumentSnapshot]]) -> None:

ระบุกลุ่มเอกสารโดยใช้ไวลด์การ์ด

ถ้าคุณต้องการแนบทริกเกอร์กับกลุ่มเอกสาร เช่น เอกสารใดๆ ใน คอลเล็กชันที่ต้องการ ให้ใช้ {wildcard} แทน รหัสเอกสาร:

Node.js

import {
  onDocumentWritten,
  Change,
  FirestoreEvent
} from "firebase-functions/v2/firestore";

exports.myfunction = onDocumentWritten("users/{userId}", (event) => {
  // If we set `/users/marie` to {name: "Marie"} then
  // event.params.userId == "marie"
  // ... and ...
  // event.data.after.data() == {name: "Marie"}
});

Python (ตัวอย่าง)

from firebase_functions.firestore_fn import (
  on_document_written,
  Event,
  Change,
  DocumentSnapshot,
)

@on_document_written(document="users/{userId}")
def myfunction(event: Event[Change[DocumentSnapshot]]) -> None:
  # If we set `/users/marie` to {name: "Marie"} then
  event.params["userId"] == "marie"  # True
  # ... and ...
  event.data.after.to_dict() == {"name": "Marie"}  # True

ในตัวอย่างนี้ เมื่อช่องใดก็ตามในเอกสารใน users มีการเปลี่ยนแปลง ช่องนั้นจะตรงกัน ไวลด์การ์ดที่ชื่อ userId

หากเอกสารใน users มีคอลเล็กชันย่อยและมีฟิลด์หนึ่งในคอลเล็กชันเหล่านั้น คอลเล็กชันย่อย เปลี่ยนเอกสารแล้ว ไม่มีการเรียกใช้ไวลด์การ์ด userId

การจับคู่ไวลด์การ์ดจะแยกออกจากเส้นทางของเอกสารและจัดเก็บไว้ใน event.params คุณอาจกำหนดไวลด์การ์ดได้มากเท่าที่ต้องการเพื่อแทนที่คอลเล็กชันที่อาจไม่เหมาะสม หรือรหัสเอกสาร เช่น

Node.js

import {
  onDocumentWritten,
  Change,
  FirestoreEvent
} from "firebase-functions/v2/firestore";

exports.myfunction = onDocumentWritten("users/{userId}/{messageCollectionId}/{messageId}", (event) => {
    // If we set `/users/marie/incoming_messages/134` to {body: "Hello"} then
    // event.params.userId == "marie";
    // event.params.messageCollectionId == "incoming_messages";
    // event.params.messageId == "134";
    // ... and ...
    // event.data.after.data() == {body: "Hello"}
});

Python (ตัวอย่าง)

from firebase_functions.firestore_fn import (
  on_document_written,
  Event,
  Change,
  DocumentSnapshot,
)

@on_document_written(document="users/{userId}/{messageCollectionId}/{messageId}")
def myfunction(event: Event[Change[DocumentSnapshot]]) -> None:
  # If we set `/users/marie/incoming_messages/134` to {body: "Hello"} then
  event.params["userId"] == "marie"  # True
  event.params["messageCollectionId"] == "incoming_messages"  # True
  event.params["messageId"] == "134"  # True
  # ... and ...
  event.data.after.to_dict() == {"body": "Hello"}

ทริกเกอร์ต้องชี้ไปที่เอกสารเสมอ แม้ว่าคุณจะใช้ไวลด์การ์ด ตัวอย่างเช่น users/{userId}/{messageCollectionId} ไม่ถูกต้องเนื่องจาก {messageCollectionId} เป็นคอลเล็กชัน แต่ users/{userId}/{messageCollectionId}/{messageId} เท่ากับ ถูกต้องเนื่องจาก {messageId} จะชี้ไปยังเอกสารเสมอ

ตัวทริกเกอร์เหตุการณ์

เรียกใช้ฟังก์ชันเมื่อมีการสร้างเอกสารใหม่

คุณสามารถเรียกให้ฟังก์ชันเริ่มทำงานทุกครั้งที่มีการสร้างเอกสารใหม่ในคอลเล็กชัน ฟังก์ชันตัวอย่างนี้จะทำงานทุกครั้งที่มีการเพิ่มโปรไฟล์ผู้ใช้ใหม่

Node.js

import {
  onDocumentCreated,
  Change,
  FirestoreEvent
} from "firebase-functions/v2/firestore";

exports.createuser = onDocumentCreated("users/{userId}", (event) => {
    // Get an object representing the document
    // e.g. {'name': 'Marie', 'age': 66}
    const snapshot = event.data;
    if (!snapshot) {
        console.log("No data associated with the event");
        return;
    }
    const data = snapshot.data();

    // access a particular field as you would any JS property
    const name = data.name;

    // perform more operations ...
});

สำหรับข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม โปรดใช้ onDocumentCreatedWithAuthContext

Python (ตัวอย่าง)

from firebase_functions.firestore_fn import (
  on_document_created,
  Event,
  DocumentSnapshot,
)

@on_document_created(document="users/{userId}")
def myfunction(event: Event[DocumentSnapshot]) -> None:
  # Get a dictionary representing the document
  # e.g. {'name': 'Marie', 'age': 66}
  new_value = event.data.to_dict()

  # Access a particular field as you would any dictionary
  name = new_value["name"]

  # Perform more operations ...

เรียกใช้ฟังก์ชันเมื่อมีการอัปเดตเอกสาร

นอกจากนี้ ยังทริกเกอร์ให้ฟังก์ชันเริ่มทำงานเมื่อมีการอัปเดตเอกสารได้อีกด้วย ฟังก์ชันตัวอย่างนี้จะเริ่มทำงานหากผู้ใช้เปลี่ยนโปรไฟล์

Node.js

import {
  onDocumentUpdated,
  Change,
  FirestoreEvent
} from "firebase-functions/v2/firestore";

exports.updateuser = onDocumentUpdated("users/{userId}", (event) => {
    // Get an object representing the document
    // e.g. {'name': 'Marie', 'age': 66}
    const newValue = event.data.after.data();

    // access a particular field as you would any JS property
    const name = newValue.name;

    // perform more operations ...
});

สำหรับข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม โปรดใช้ onDocumentUpdatedWithAuthContext

Python (ตัวอย่าง)

from firebase_functions.firestore_fn import (
  on_document_updated,
  Event,
  Change,
  DocumentSnapshot,
)

@on_document_updated(document="users/{userId}")
def myfunction(event: Event[Change[DocumentSnapshot]]) -> None:
  # Get a dictionary representing the document
  # e.g. {'name': 'Marie', 'age': 66}
  new_value = event.data.after.to_dict()

  # Access a particular field as you would any dictionary
  name = new_value["name"]

  # Perform more operations ...

เรียกใช้ฟังก์ชันเมื่อลบเอกสาร

นอกจากนี้ คุณยังเรียกใช้ฟังก์ชันเมื่อมีการลบเอกสารได้ด้วย ตัวอย่างนี้ เริ่มทำงานเมื่อผู้ใช้ลบโปรไฟล์ผู้ใช้

Node.js

import {
  onDocumentDeleted,
  Change,
  FirestoreEvent
} from "firebase-functions/v2/firestore";

exports.deleteuser = onDocumentDeleted("users/{userId}", (event) => {
    // Get an object representing the document
    // e.g. {'name': 'Marie', 'age': 66}
    const snap =  event.data;
    const data =  snap.data();

    // perform more operations ...
});

สำหรับข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม โปรดใช้ onDocumentDeletedWithAuthContext

Python (ตัวอย่าง)

from firebase_functions.firestore_fn import (
  on_document_deleted,
  Event,
  DocumentSnapshot,
)

@on_document_deleted(document="users/{userId}")
def myfunction(event: Event[DocumentSnapshot|None]) -> None:
  # Perform more operations ...

เรียกใช้ฟังก์ชันสำหรับการเปลี่ยนแปลงทั้งหมดในเอกสาร

หากไม่สนใจประเภทเหตุการณ์ที่เริ่มทำงาน ก็เลือกฟังทั้งหมดได้ การเปลี่ยนแปลงในเอกสาร Cloud Firestore โดยใช้ "เอกสารที่เขียน" กิจกรรม ทริกเกอร์ ฟังก์ชันตัวอย่างนี้จะเริ่มทำงานเมื่อมีการสร้าง อัปเดต หรือลบผู้ใช้

Node.js

import {
  onDocumentWritten,
  Change,
  FirestoreEvent
} from "firebase-functions/v2/firestore";

exports.modifyuser = onDocumentWritten("users/{userId}", (event) => {
    // Get an object with the current document values.
    // If the document does not exist, it was deleted
    const document =  event.data.after.data();

    // Get an object with the previous document values
    const previousValues =  event.data.before.data();

    // perform more operations ...
});

สำหรับข้อมูลการตรวจสอบสิทธิ์เพิ่มเติม โปรดใช้ onDocumentWrittenWithAuthContext

Python (ตัวอย่าง)

from firebase_functions.firestore_fn import (
  on_document_written,
  Event,
  Change,
  DocumentSnapshot,
)

@on_document_written(document="users/{userId}")
def myfunction(event: Event[Change[DocumentSnapshot | None]]) -> None:
  # Get an object with the current document values.
  # If the document does not exist, it was deleted.
  document = (event.data.after.to_dict()
              if event.data.after is not None else None)

  # Get an object with the previous document values.
  # If the document does not exist, it was newly created.
  previous_values = (event.data.before.to_dict()
                     if event.data.before is not None else None)

  # Perform more operations ...

ข้อมูลการอ่านและการเขียน

เมื่อมีการทริกเกอร์ฟังก์ชัน ฟังก์ชันดังกล่าวจะแสดงภาพรวมของข้อมูลที่เกี่ยวข้องกับฟังก์ชัน กิจกรรม คุณสามารถใช้สแนปชอตนี้เพื่ออ่านหรือเขียนในเอกสารที่ ทริกเกอร์เหตุการณ์ หรือใช้ Firebase Admin SDK เพื่อเข้าถึงส่วนอื่นๆ ฐานข้อมูลของคุณ

ข้อมูลเหตุการณ์

กำลังอ่านข้อมูล

เมื่อมีการทริกเกอร์ฟังก์ชัน คุณอาจต้องการรับข้อมูลจากเอกสารที่ ได้รับการอัปเดต หรือรับข้อมูลก่อนที่จะอัปเดต คุณสามารถรับข้อมูลก่อนหน้านี้โดยใช้ event.data.before ซึ่งมีสแนปชอตเอกสารก่อนการอัปเดต ในทำนองเดียวกัน event.data.after จะมีสถานะสแนปชอตเอกสารหลังจาก อัปเดต

Node.js

exports.updateuser2 = onDocumentUpdated("users/{userId}", (event) => {
    // Get an object with the current document values.
    // If the document does not exist, it was deleted
    const newValues =  event.data.after.data();

    // Get an object with the previous document values
    const previousValues =  event.data.before.data();
});

Python (ตัวอย่าง)

@on_document_updated(document="users/{userId}")
def myfunction(event: Event[Change[DocumentSnapshot]]) -> None:
  # Get an object with the current document values.
  new_value = event.data.after.to_dict()

  # Get an object with the previous document values.
  prev_value = event.data.before.to_dict()

คุณจะเข้าถึงพร็อพเพอร์ตี้ได้เช่นเดียวกับในออบเจ็กต์อื่นๆ หรือคุณอาจเลือก ใช้ฟังก์ชัน get เพื่อเข้าถึงช่องข้อมูลที่ต้องการได้

Node.js

// Fetch data using standard accessors
const age = event.data.after.data().age;
const name = event.data.after.data()['name'];

// Fetch data using built in accessor
const experience = event.data.after.data.get('experience');

Python (ตัวอย่าง)

# Get the value of a single document field.
age = event.data.after.get("age")

# Convert the document to a dictionary.
age = event.data.after.to_dict()["age"]

ข้อมูลการเขียน

การเรียกใช้ฟังก์ชันแต่ละรายการจะเชื่อมโยงกับเอกสารเฉพาะในเอกสาร ฐานข้อมูล Cloud Firestore คุณเข้าถึงเอกสารนั้นได้ใน สแนปชอตกลับไปที่ฟังก์ชัน

การอ้างอิงเอกสารประกอบด้วยเมธอดต่างๆ เช่น update(), set() และ remove() เพื่อให้คุณแก้ไขเอกสารที่เรียกใช้ฟังก์ชันได้

Node.js

import { onDocumentUpdated } from "firebase-functions/v2/firestore";

exports.countnamechanges = onDocumentUpdated('users/{userId}', (event) => {
  // Retrieve the current and previous value
  const data = event.data.after.data();
  const previousData = event.data.before.data();

  // We'll only update if the name has changed.
  // This is crucial to prevent infinite loops.
  if (data.name == previousData.name) {
    return null;
  }

  // Retrieve the current count of name changes
  let count = data.name_change_count;
  if (!count) {
    count = 0;
  }

  // Then return a promise of a set operation to update the count
  return data.after.ref.set({
    name_change_count: count + 1
  }, {merge: true});

});

Python (ตัวอย่าง)

@on_document_updated(document="users/{userId}")
def myfunction(event: Event[Change[DocumentSnapshot]]) -> None:
  # Get the current and previous document values.
  new_value = event.data.after
  prev_value = event.data.before

  # We'll only update if the name has changed.
  # This is crucial to prevent infinite loops.
  if new_value.get("name") == prev_value.get("name"):
      return

  # Retrieve the current count of name changes
  count = new_value.to_dict().get("name_change_count", 0)

  # Update the count
  new_value.reference.update({"name_change_count": count + 1})

เข้าถึงข้อมูลการตรวจสอบสิทธิ์ของผู้ใช้

หากใช้หนึ่งในประเภทเหตุการณ์ต่อไปนี้ คุณจะเข้าถึง ข้อมูลการตรวจสอบสิทธิ์ผู้ใช้เกี่ยวกับผู้ใช้หลักที่ทริกเกอร์เหตุการณ์ ข้อมูลนี้เป็นส่วนเพิ่มเติมจากข้อมูลที่แสดงในเหตุการณ์ฐาน

Node.js

  • onDocumentCreatedWithAuthContext
  • onDocumentWrittenWithAuthContext
  • onDocumentDeletedWithAuthContext
  • onDocumentUpdatedWithAuthContext

Python (ตัวอย่าง)

  • on_document_created_with_auth_context
  • on_document_updated_with_auth_context
  • on_document_deleted_with_auth_context
  • on_document_written_with_auth_context

สำหรับรายละเอียดเกี่ยวกับข้อมูลที่ใช้ได้ในบริบทการตรวจสอบสิทธิ์ โปรดดู บริบทการตรวจสอบสิทธิ์ ตัวอย่างต่อไปนี้แสดงวิธีเรียกข้อมูลการตรวจสอบสิทธิ์

Node.js

import { onDocumentWrittenWithAuthContext } from "firebase-functions/v2/firestore"

exports.syncUser = onDocumentWrittenWithAuthContext("users/{userId}", (event) => {
    const snapshot = event.data.after;
    if (!snapshot) {
        console.log("No data associated with the event");
        return;
    }
    const data = snapshot.data();

    // retrieve auth context from event
    const { authType, authId } = event;

    let verified = false;
    if (authType === "system") {
      // system-generated users are automatically verified
      verified = true;
    } else if (authType === "unknown" || authType === "unauthenticated") {
      // admin users from a specific domain are verified
      if (authId.endsWith("@example.com")) {
        verified = true;
      }
    }

    return data.after.ref.set({
        created_by: authId,
        verified,
    }, {merge: true}); 
}); 

Python (ตัวอย่าง)

@on_document_updated_with_auth_context(document="users/{userId}")
def myfunction(event: Event[Change[DocumentSnapshot]]) -> None:

  # Get the current and previous document values.
  new_value = event.data.after
  prev_value = event.data.before

  # Get the auth context from the event
  user_auth_type = event.auth_type
  user_auth_id = event.auth_id

ข้อมูลที่อยู่นอกเหตุการณ์ทริกเกอร์

Cloud Functions จะทำงานในสภาพแวดล้อมที่เชื่อถือได้ นั่นคือ ได้รับสิทธิ์ให้เป็นบัญชีบริการในโปรเจ็กต์ของคุณ และคุณสามารถดำเนินการอ่านและ เขียนโดยใช้ Firebase Admin SDK ดังนี้

Node.js

const { initializeApp } = require('firebase-admin/app');
const { getFirestore, Timestamp, FieldValue } = require('firebase-admin/firestore');

initializeApp();
const db = getFirestore();

exports.writetofirestore = onDocumentWritten("some/doc", (event) => {
    db.doc('some/otherdoc').set({ ... });
  });

  exports.writetofirestore = onDocumentWritten('users/{userId}', (event) => {
    db.doc('some/otherdoc').set({
      // Update otherdoc
    });
  });

Python (ตัวอย่าง)

from firebase_admin import firestore, initialize_app
import google.cloud.firestore

initialize_app()

@on_document_written(document="some/doc")
def myfunction(event: Event[Change[DocumentSnapshot | None]]) -> None:
  firestore_client: google.cloud.firestore.Client = firestore.client()
  firestore_client.document("another/doc").set({
      # ...
  })

ข้อจำกัด

โปรดทราบข้อจำกัดต่อไปนี้สำหรับทริกเกอร์ Cloud Firestore สำหรับ Cloud Functions

  • Cloud Functions (รุ่นที่ 1) ต้องมี "(ค่าเริ่มต้น)" อยู่แล้ว ฐานข้อมูลในโหมดดั้งเดิมของ Firestore แต่ไม่ รองรับฐานข้อมูลที่มีชื่อใน Cloud Firestore หรือโหมด Datastore โปรดใช้ Cloud Functions (รุ่นที่ 2) เพื่อกำหนดค่าเหตุการณ์ในกรณีเช่นนี้
  • เราไม่รับประกันว่าจะสั่งซื้อ การเปลี่ยนแปลงอย่างรวดเร็วจะเรียกใช้การเรียกใช้ฟังก์ชันได้ใน คำสั่งซื้อที่ไม่คาดคิด
  • มีการส่งเหตุการณ์อย่างน้อย 1 ครั้ง แต่เหตุการณ์เดียวอาจทําให้ การเรียกใช้ฟังก์ชันหลายรายการ หลีกเลี่ยง ครั้งเดียวเท่านั้น และเขียน ฟังก์ชันนิรนาม
  • Cloud Firestore ในโหมด Datastore ต้องใช้ Cloud Functions (รุ่นที่ 2) Cloud Functions (รุ่นที่ 1) ไม่มี รองรับโหมด Datastore
  • ทริกเกอร์เชื่อมโยงกับฐานข้อมูลเดียว คุณสร้างทริกเกอร์ที่ตรงกับหลายฐานข้อมูลไม่ได้
  • การลบฐานข้อมูลจะไม่ลบทริกเกอร์สำหรับฐานข้อมูลนั้นโดยอัตโนมัติ ทริกเกอร์จะหยุดส่งเหตุการณ์แต่จะยังคงมีอยู่จนกว่าคุณจะลบทริกเกอร์
  • หากเหตุการณ์ที่ตรงกันเกินขนาดคำขอสูงสุด ระบบจะดำเนินการ อาจไม่มีการส่งเหตุการณ์ไปยัง Cloud Functions (รุ่นที่ 1)
    • ระบบไม่ได้ส่งเหตุการณ์เนื่องจากขนาดคำขอไว้ในบันทึกแพลตฟอร์ม และนับรวมกับการใช้งานบันทึกสำหรับโปรเจ็กต์
    • คุณสามารถค้นหาบันทึกเหล่านี้ได้ในเครื่องมือสำรวจบันทึกที่มีข้อความ "ส่งเหตุการณ์ไปยังไม่ได้" Cloud Function เนื่องจากขนาดเกินขีดจำกัดสำหรับรุ่นที่ 1..." จาก error ความรุนแรง ชื่อฟังก์ชันจะอยู่ในช่อง functionName ถ้า ฟิลด์ receiveTimestamp ยังคงอยู่ภายใน 1 ชั่วโมงจากนี้ คุณสามารถอนุมาน เนื้อหาเหตุการณ์จริงโดยการอ่านเอกสารที่เป็นปัญหา ก่อนและหลังการประทับเวลา
    • หากต้องการหลีกเลี่ยงความถี่ดังกล่าว โปรดทำดังนี้
      • ย้ายข้อมูลและอัปเกรดเป็น Cloud Functions (รุ่นที่ 2)
      • ลดขนาดเอกสาร
      • ลบ Cloud Functions ที่มีปัญหา
    • คุณปิดการบันทึกได้โดยใช้การยกเว้น แต่โปรดทราบว่าระบบจะยังไม่นำส่งกิจกรรมที่ไม่เหมาะสม