When onDocumentCreated
is triggered for a nested document, the parent document has not been created yet
#1658
Labels
onDocumentCreated
is triggered for a nested document, the parent document has not been created yet
#1658
When
onDocumentCreated
is triggered for a nested document like/countries/{countryId}/cities/{cityId}
, its parents, here the/countries/{countryId}
document, should already exist, as suggested by the documentation (see the Expected behavior section). But tests show that if the country document didn't already exist (i.e. when creating the first city within it), it won't already exist at the time the trigger executes.Related issues
None.
[REQUIRED] Version info
node: v22.12.0
firebase-functions: 6.2.0
firebase-tools: 13.29.1
firebase-admin: 13.0.2
[REQUIRED] Test case
https://github.com/dandv/onDocumentCreated-parent-bug
[REQUIRED] Steps to reproduce
Check the logs at https://console.cloud.google.com/logs/query?project=ondocumentcreated-bug
and
countryDoc.exists: false
(screenshot below).[REQUIRED] Expected behavior
Given that the city document does exist (see the screenshot) when the trigger starts execution, the parent document (
/countries/USA
) should already exist, as the documentation states:The Trigger a function when a new document is created example doesn't mention anything about the parent document of newly created nested documents not existing yet.
If the code is somehow WAI, then the documentation should be updated to mention this counter-intuitive behavior specifically.
[REQUIRED] Actual behavior
The output above is produced by the code below:
Were you able to successfully deploy your functions?
Yes, the function was deployed without errors, and is triggered as seen in the screenshot above.
The text was updated successfully, but these errors were encountered: