CodexBloom - Programming Q&A Platform

GCP Cloud Functions not triggering from Firestore document changes with JavaScript SDK

👀 Views: 59 💬 Answers: 1 📅 Created: 2025-06-10
google-cloud-functions firestore firebase JavaScript

I'm experiencing issues with my GCP Cloud Function not being triggered when documents in Firestore are updated. I've set up the function to respond to `onUpdate` events, but it appears to be completely unresponsive. Here's the relevant code snippet for the Cloud Function: ```javascript const functions = require('firebase-functions'); const admin = require('firebase-admin'); admin.initializeApp(); exports.onDocumentUpdate = functions.firestore.document('myCollection/{docId}').onUpdate((change, context) => { const newValue = change.after.data(); console.log('Document updated with new value:', newValue); return null; }); ``` I have deployed the function using the Firebase CLI with the command `firebase deploy --only functions`, and I can see that it's deployed successfully. However, when I update a document in `myCollection`, there's no output in the logs, and the function seems to be dormant. I verified that Firestore has the necessary permissions for the Cloud Functions service account. I've also checked the Firestore rules, which allow reads and writes for the authenticated users. Despite this, the function does not trigger at all. I even tried adding a simple HTTP trigger to ensure my deployment is working, and that one works fine. I’ve also tried adding a few debug logs at different points in the function, but none of them are executed. Is there something I might be missing in the setup? Could the triggers take time to propagate, or is there a specific configuration I need to check? Any insights would be appreciated!