My function:
export const myFunction = onDocumentDeleted( 'myDocuments/{myDocumentID}', async ( event: FirestoreEvent< QueryDocumentSnapshot | undefined, { flowID: string } >, ): Promise<void> => { console.log('Event is:', JSON.stringify(event)); const snapshot = event.data as QueryDocumentSnapshot<Flow>; console.log('Snapshot is:', JSON.stringify(snapshot)); }, );
My deploy script:
FUNCTION_NAME=my-function ENTRY_POINT=myFunction PROJECT_ID=my-project gcloud functions deploy ${FUNCTION_NAME} \ --gen2 \ --runtime=nodejs20 \ --region=europe-west3 \ --trigger-location=eur3 \ --source=./deploy \ --entry-point=${ENTRY_POINT} \ --project=${PROJECT_ID} \ --env-vars-file=.env.stage.yaml \ --trigger-event-filters=type=google.cloud.firestore.document.v1.deleted \ --trigger-event-filters=database='(default)' \ --trigger-event-filters-path-pattern=document='myDocuments/{myDocumentID}' \ --allow-unauthenticated \
The result:
Hi @Meros,
Welcome to Google Cloud Community!
It seems that it has already had an answer from Stack Overflow. Here's the post from the community member:
The code you're writing is using the Firebase SDK. It can only be deployed using the Firebase CLI. You can't use gcloud to deploy functions that use the Firebase SDK.
If you want to deploy a function with gcloud, you must follow the instructions in the GCP documentation. If you want to deploy a function using a Firebase SDK, you must use the Firebase CLI. Also I think you will do better to follow the Firestore examples on a different page of Firebase docs.
Hope this helps.