Cloud Functions की मदद से, Cloud Firestore में मौजूद इवेंट को मैनेज किया जा सकता है. इसके लिए, क्लाइंट कोड को अपडेट करने की ज़रूरत नहीं होती. दस्तावेज़ के स्नैपशॉट वाले इंटरफ़ेस या एडमिन SDK टूल की मदद से, Cloud Firestore में बदलाव किए जा सकते हैं.
आम तौर पर, Cloud Firestore का कोई फ़ंक्शन ये काम करता है:
- किसी खास दस्तावेज़ में होने वाले बदलावों का इंतज़ार करता है.
- कोई इवेंट होने पर ट्रिगर होता है और अपने टास्क पूरे करता है.
- एक डेटा ऑब्जेक्ट लेता है. इसमें, तय किए गए दस्तावेज़ में सेव किए गए डेटा का स्नैपशॉट होता है. लिखने या अपडेट करने से जुड़े इवेंट के लिए, डेटा ऑब्जेक्ट में दो स्नैपशॉट होते हैं. इनमें, इवेंट ट्रिगर होने से पहले और बाद की डेटा की स्थिति दिखती है.
Firestore इंस्टेंस की जगह और फ़ंक्शन की जगह के बीच की दूरी की वजह से, नेटवर्क की लेटेन्सी बढ़ सकती है. परफ़ॉर्मेंस को ऑप्टिमाइज़ करने के लिए, जहां लागू हो वहां फ़ंक्शन की जगह तय करें.
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 के किसी दस्तावेज़ को अपडेट करने पर, अगर डेटा में कोई बदलाव नहीं होता है, तो अपडेट या लिखने से जुड़ा कोई इवेंट जनरेट नहीं होता. खास फ़ील्ड में इवेंट नहीं जोड़े जा सकते.
अगर आपने अब तक Cloud Functions for Firebase के लिए कोई प्रोजेक्ट चालू नहीं किया है, तो Cloud Functions for Firebase (2nd gen) का इस्तेमाल शुरू करना लेख पढ़ें. इससे आपको 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} मान्य है
क्योंकि {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 ...
किसी दस्तावेज़ में होने वाले सभी बदलावों के लिए, कोई फ़ंक्शन ट्रिगर करना
अगर आपको ट्रिगर होने वाले इवेंट के टाइप से कोई फ़र्क़ नहीं पड़ता है, तो "दस्तावेज़ लिखा गया" इवेंट ट्रिगर का इस्तेमाल करके, 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
onDocumentCreatedWithAuthContextonDocumentWrittenWithAuthContextonDocumentDeletedWithAuthContextonDocumentUpdatedWithAuthContext
Python
on_document_created_with_auth_contexton_document_updated_with_auth_contexton_document_deleted_with_auth_contexton_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 (1st gen) के लिए, Firestore के नेटिव मोड में "(default)" डेटाबेस का होना ज़रूरी है. यह नाम वाले डेटाबेस या Datastore मोड के साथ काम नहीं करता.Cloud Firestore ऐसे मामलों में, इवेंट कॉन्फ़िगर करने के लिए, Cloud Functions (2nd gen) का इस्तेमाल करें.
- Cloud Functions और Cloud Firestore के ट्रिगर के साथ, अलग-अलग प्रोजेक्ट सेट अप करना मुमकिन नहीं है. Cloud Firestore के ट्रिगर को सेट अप करने के लिए, Cloud Functions को एक ही प्रोजेक्ट में होना चाहिए.
- इवेंट के क्रम की कोई गारंटी नहीं है. तेज़ी से होने वाले बदलावों की वजह से, फ़ंक्शन कॉल अनचाहे क्रम में ट्रिगर हो सकते हैं.
- इवेंट कम से कम एक बार डिलीवर किए जाते हैं. हालांकि, किसी एक इवेंट की वजह से, कई फ़ंक्शन कॉल हो सकते हैं. एक बार ही होने वाली प्रोसेस पर निर्भर न रहें और आइडमपोटेंट फ़ंक्शन लिखें.
- Cloud Firestore Datastore मोड में के लिए, Cloud Functions (2nd gen) की ज़रूरत होती है. Cloud Functions (1st gen), Datastore मोड के साथ काम नहीं करता.
- कोई ट्रिगर, किसी एक डेटाबेस से जुड़ा होता है. ऐसा ट्रिगर नहीं बनाया जा सकता जो एक से ज़्यादा डेटाबेस से मैच करे.
- किसी डेटाबेस को मिटाने पर, उस डेटाबेस के लिए कोई ट्रिगर अपने-आप नहीं मिटता. ट्रिगर, इवेंट डिलीवर करना बंद कर देता है. हालांकि, जब तक ट्रिगर को मिटाया नहीं जाता, तब तक वह मौजूद रहता है.
- अगर मैच किया गया कोई इवेंट, अनुरोध के तय साइज़ से ज़्यादा है, तो हो सकता है कि वह
इवेंट Cloud Functions (1st gen) को डिलीवर न किया जाए.
- अनुरोध के साइज़ की वजह से डिलीवर न किए गए इवेंट, प्लैटफ़ॉर्म के लॉग में लॉग किए जाते हैं. साथ ही, इन्हें प्रोजेक्ट के लिए लॉग के इस्तेमाल में गिना जाता है.
- इन लॉग को, लॉग एक्सप्लोरर में देखा जा सकता है. इनमें,
errorगंभीरता वाला यह मैसेज दिखता है: "Event cannot deliver to Cloud function due to size exceeding the limit for 1st gen..."functionNameफ़ील्ड में, फ़ंक्शन का नाम देखा जा सकता है. अगरreceiveTimestampफ़ील्ड, अब से एक घंटे के अंदर का है, तो सवाल में मौजूद दस्तावेज़ को टाइमस्टैंप से पहले और बाद के स्नैपशॉट के साथ पढ़कर, इवेंट के असल कॉन्टेंट का अनुमान लगाया जा सकता है. - इस समस्या से बचने के लिए, ये काम किए जा सकते हैं:
- Cloud Functions (2nd gen) पर माइग्रेट और अपग्रेड करें
- दस्तावेज़ का साइज़ कम करें
- सवाल में मौजूद Cloud Functions को मिटाएं
- एक्सक्लूज़न का इस्तेमाल करके, लॉगिंग की सुविधा बंद की जा सकती है. हालांकि, ध्यान दें कि समस्या पैदा करने वाले इवेंट अब भी डिलीवर नहीं किए जाएंगे.