Cloud Functions: Firestore onCreate not triggering as expected (Node 16 environment)

1,352 views
Skip to first unread message

Manjhunath Ravi

unread,
Jul 22, 2022, 8:11:16 PM7/22/22
to Firebase Google Group
Hey folks!

I'm working on.a project where I need to do some actions on creation of specific document in a collection. So I setup onCreate for Firestore using Firebase functions.

The problem is that onCreate is not triggering as expected. 

The funny thing is onCreate gets triggered if I create a document manually using Firebase console.

It is only when I create documents programmatically does the onCreate fail to trigger.

Any help is appreciated!

Cheers,
Manjhunath

Manjhunath Ravi

unread,
Jul 23, 2022, 2:33:15 PM7/23/22
to Firebase Google Group
My cloud functions region is US-Central1

Bristlepath S

unread,
Jul 24, 2022, 4:08:44 PM7/24/22
to Firebase Google Group
We would probably have to see some code to assist you.  I use onCreate for my document creation and it triggers the firebase function just fine for me.
If it is triggering from the console, I would suspect that your iam/service account is not set up properly with your function.
It's not easy to figure that out as the documentation is badly written.  But it could be one reason console can access but not your .js file.

Manjhunath Ravi

unread,
Jul 25, 2022, 11:06:12 AM7/25/22
to Firebase Google Group
Thank you!

I checked the service account permissions and the service account associated with firebase does have Cloud Functions Admin Role...

Not sure what the problem is! 

Here is my code for onCreate trigger:
 Screenshot 2022-07-25 at 1.18.21 PM.png


Cheers,
Manjhunath

Michael Bleigh

unread,
Jul 25, 2022, 11:23:17 AM7/25/22
to Firebase Google Group
When you create documents programmatically, do they then show up in the console exactly as they do when you add them manually? Same collection, all that? Have you checked the logs for the function to see if there are any errors or unexpected things there?

If events are being triggered from adding documents in the console, there is likely nothing wrong with your function's connection/trigger. The console uses the same SDKs to write to Firestore as your code does. I suspect that there is an undiscovered error somewhere along the way, or perhaps you are writing to a different collection than your trigger matches.

Cheers,
Michael

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/501eb297-765a-438d-9074-f135171f209an%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages