I’m currently using Firebase Functions to listen to document changes in Firestore, but I’m facing an issue where my function is triggered for every document change in every collection in the database rather than just the intended specific collection. Not sure what I am missing here. Here’s a simplified version of my code:
const { onDocumentWritten } = require("firebase-functions/v2/firestore");
exports.processDocumentChange = onDocumentWritten(
"/targetCollection/{docId}",
(event) => {
const docId = event.params.docId;
console.log("Document written: ", docId);
if (!docId) {
console.log("Document ID not found");
return;
}
performActionBasedOnDocId(docId);
}
);