Cloud Firestore ট্রিগার

Cloud Functions-এর সাহায্যে, আপনি ক্লায়েন্ট কোড আপডেট করার প্রয়োজন ছাড়াই Cloud Firestore-এ ইভেন্ট ম্যানেজ করতে পারবেন। আপনি ডকুমেন্ট স্ন্যাপশট ইন্টারফেস বা Admin SDK-এর মাধ্যমে Cloud Firestore-এ পরিবর্তন করতে পারবেন।

সাধারণ লাইফসাইকেলে, Cloud Firestore ফাংশন নিম্নলিখিত কাজগুলি করে:

  1. নির্দিষ্ট ডকুমেন্টে পরিবর্তনের জন্য অপেক্ষা করে।
  2. কোনও ইভেন্ট ঘটলে ট্রিগার হয় এবং নিজের কাজ করে।
  3. নির্দিষ্ট ডকুমেন্টে সেভ করা ডেটার স্ন্যাপশট থাকা ডেটা অবজেক্ট পায়। ইভেন্ট লেখার বা আপডেট করার জন্য, ডেটা অবজেক্টে দুটি স্ন্যাপশট থাকে যা ট্রিগার করা ইভেন্টের আগে ও পরে ডেটার অবস্থা দেখায়।

Firestore ইনস্ট্যান্সের লোকেশন ও ফাংশনের লোকেশনের মধ্যবর্তী দূরত্ব উল্লেখযোগ্য নেটওয়ার্ক লেটেন্সি তৈরি করতে পারে। পারফর্ম্যান্স অপ্টিমাইজ করতে, প্রযোজ্য হলে ফাংশন লোকেশন নির্দিষ্ট করার কথা বিবেচনা করুন।

Cloud Firestore ফাংশন ট্রিগার

Cloud Functions for Firebase SDK নিম্নলিখিত Cloud Firestore ইভেন্ট ট্রিগার এক্সপোর্ট করে যাতে আপনি নির্দিষ্ট Cloud Firestore ইভেন্টের সাথে যুক্ত হ্যান্ডলার তৈরি করতে পারেন:

Node.js

ইভেন্টের ধরন Trigger
onDocumentCreated কোনও ডকুমেন্টে প্রথমবার কিছু লেখা হলে এটি ট্রিগার হয়।
onDocumentUpdated আগে থেকেই থাকা কোনও ডকুমেন্টের ভ্যালু পরিবর্তন হলে ট্রিগার করা হয়।
onDocumentDeleted কোনও ডকুমেন্ট মুছে দেওয়া হলে ট্রিগার হয়।
onDocumentWritten onDocumentCreated, onDocumentUpdated বা onDocumentDeleted ট্রিগার করা হলে ট্রিগার হয়।
onDocumentCreatedWithAuthContext onDocumentCreated অতিরিক্ত যাচাইকরণ সংক্রান্ত তথ্য সহ
onDocumentWrittenWithAuthContext onDocumentWritten অতিরিক্ত যাচাইকরণ সংক্রান্ত তথ্য সহ
onDocumentDeletedWithAuthContext onDocumentDeleted অতিরিক্ত যাচাইকরণ সংক্রান্ত তথ্য সহ
onDocumentUpdatedWithAuthContext onDocumentUpdated অতিরিক্ত যাচাইকরণ সংক্রান্ত তথ্য সহ

Python

ইভেন্টের ধরন Trigger
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 ডকুমেন্টে কোনও আপডেট করা হলে, যেখানে ডেটা পরিবর্তিত হয় না (কোনও অপারেশন না করা), সেখানে কোনও আপডেট বা রাইট ইভেন্ট তৈরি হয় না। নির্দিষ্ট ফিল্ডে ইভেন্ট যোগ করা সম্ভব নয়।

Cloud Functions for Firebase-এর জন্য এখনও কোনও প্রোজেক্ট চালু না করে থাকলে, আপনার Cloud Functions for Firebase প্রোজেক্ট কনফিগার ও সেট-আপ করতে Cloud Functions for Firebase (২য় জেনারেশন) ব্যবহার করা শুরু করুন লিঙ্কটি পড়ুন।

Cloud Firestore-ট্রিগার করা ফাংশন লেখা

ফাংশন ট্রিগার সংজ্ঞায়িত করা

Cloud Firestore ট্রিগার নির্ধারণ করতে, একটি ডকুমেন্ট পাথ ও ইভেন্টের ধরন নির্দিষ্ট করুন:

Node.js

const {
  onDocumentWritten,
  onDocumentCreated,
  onDocumentUpdated,
  onDocumentDeleted,
  Change,
  FirestoreEvent
} = require('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

const {
  onDocumentWritten,
  Change,
  FirestoreEvent
} = require('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

const {
  onDocumentWritten,
  Change,
  FirestoreEvent
} = require('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

const {
  onDocumentWritten,
  Change,
  FirestoreEvent
} = require('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} is সঠিক, কারণ {messageId} সবসময় কোনও ডকুমেন্টের দিকে পয়েন্ট করে।

ইভেন্ট ট্রিগার

নতুন ডকুমেন্ট তৈরি হলে কোনও ফাংশন ট্রিগার করা

কোনও সংগ্রহে নতুন ডকুমেন্ট তৈরি হলে, আপনি যেকোনও সময় ফাংশন ট্রিগার করতে পারবেন। নতুন ব্যবহারকারীর প্রোফাইল যোগ করা হলে এই উদাহরণ ফাংশনটি প্রতিবার ট্রিগার হয়:

Node.js

const {
  onDocumentCreated,
  Change,
  FirestoreEvent
} = require('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

const {
  onDocumentUpdated,
  Change,
  FirestoreEvent
} = require('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

const {
  onDocumentDeleted,
  Change,
  FirestoreEvent
} = require('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 ...

ডকুমেন্টে করা সব পরিবর্তনের জন্য ফাংশন ট্রিগার করা

ফায়ার করা ইভেন্টের ধরন নিয়ে আপনি চিন্তিত না হলে, "document written" ইভেন্ট ট্রিগার ব্যবহার করে Cloud Firestore ডকুমেন্টে হওয়া সব পরিবর্তন শুনতে পারেন। ব্যবহারকারী তৈরি, আপডেট বা মুছে দেওয়া হলে এই উদাহরণ ফাংশন ফায়ার করে:

Node.js

const {
  onDocumentWritten,
  Change,
  FirestoreEvent
} = require('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

const {onDocumentUpdated} = require('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 event.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

const {onDocumentWrittenWithAuthContext} = require('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 Functions-এর জন্য Cloud Firestore ট্রিগার সংক্রান্ত নিম্নলিখিত সীমাবদ্ধতাগুলি মনে রাখবেন:

  • Cloud Functions (ফার্স্ট জেনারেশন) পূর্বশর্ত হল Firestore নেটিভ মোডে আগে থেকে থাকা "(ডিফল্ট)" ডেটাবেস। এটি Cloud Firestoreনামযুক্ত ডেটাবেস বা Datastore মোড সাপোর্ট করে না। এই ধরনের ক্ষেত্রে ইভেন্ট কনফিগার করতে Cloud Functions (2nd gen) ব্যবহার করুন।
  • Cloud Functions এবং Cloud Firestore ট্রিগার সহ ক্রস প্রজেক্ট সেট-আপ একটি সীমাবদ্ধতা। Cloud Firestore ট্রিগার Cloud Functions সেট-আপ করতে, সেটি একই প্রোজেক্টে থাকতে হবে।
  • অর্ডার করার ব্যাপারে কোনও গ্যারেন্টি নেই। দ্রুত পরিবর্তন হলে, অপ্রত্যাশিত ক্রমে ফাংশন ইনভোকেশন ট্রিগার হতে পারে।
  • ইভেন্ট অন্তত একবার ডেলিভার করা হয়, কিন্তু একটি ইভেন্টের ফলে একাধিক ফাংশন ইনভোকেশন হতে পারে। "ঠিক একবার" মেকানিজমের উপর নির্ভর করা এড়িয়ে চলুন এবং আইডেমপোটেন্ট ফাংশন লিখুন।
  • Cloud Firestore Datastore মোডে Cloud Functions (2nd gen) প্রয়োজন। Cloud Functions (ফার্স্ট জেনারেশন) Datastore মোডে কাজ করে না।
  • একটি ট্রিগার একটি ডেটাবেসের সাথে যুক্ত থাকে। আপনি এমন কোনও ট্রিগার তৈরি করতে পারবেন না যা একাধিক ডেটাবেসের সাথে ম্যাচ করে।
  • কোনও ডেটাবেস মুছে দিলে, সেই ডেটাবেসের জন্য কোনও ট্রিগার অটোমেটিক মুছে যায় না। ট্রিগার মুছে না দেওয়া পর্যন্ত ট্রিগার ইভেন্ট ডেলিভার করা বন্ধ করে দেয়, কিন্তু সেটি থেকে যায়।
  • ম্যাচ করা ইভেন্ট অনুরোধের সর্বাধিক সাইজ-এর থেকে বড় হলে, Cloud Functions (1st gen)-এ ইভেন্ট ডেলিভার করা নাও হতে পারে।
    • অনুরোধের সাইজ বড় হওয়ার কারণে ডেলিভার করা যায়নি এমন ইভেন্ট প্ল্যাটফর্ম লগে লগ করা হয় এবং প্রজেক্টের জন্য লগ ব্যবহারের মধ্যে গণনা করা হয়।
    • আপনি এই লগগুলি, লগ এক্সপ্লোরারে "1st gen-এর জন্য নির্ধারিত সীমা অতিক্রম করার কারণে ইভেন্ট ক্লাউড ফাংশনে ডেলিভার করা যাচ্ছে না..." মেসেজ সহ error গুরুত্বের সাথে দেখতে পাবেন। আপনি functionName ফিল্ডের মধ্যে ফাংশনের নাম দেখতে পাবেন। যদি receiveTimestamp ফিল্ডটি এখনও এক ঘণ্টার মধ্যে থাকে, তাহলে আপনি টাইমস্ট্যাম্পের আগে ও পরে স্ন্যাপশট সহ প্রশ্নযুক্ত ডকুমেন্টটি পড়ে আসল ইভেন্ট কন্টেন্ট সম্পর্কে জানতে পারবেন।
    • এই ধরনের ক্যাডেন্স এড়াতে, আপনি:
      • Cloud Functions (2nd gen)-এ মাইগ্রেট ও আপগ্রেড করা
      • ডকুমেন্টের সাইজ কমানো
      • যে Cloud Functions নিয়ে প্রশ্ন উঠেছে সেটি মুছে দিন
    • আপনি বাদ দেওয়া ব্যবহার করে লগিং বন্ধ করতে পারেন তবে মনে রাখবেন যে সমস্যা সৃষ্টিকারী ইভেন্টগুলি এখনও ডেলিভার করা হবে না।