Below is an explanation and a couple of suggestions to help troubleshoot this behavior.
What to Expect
A trigger defined as
exports.createAggrIngr = onDocumentCreated("course/{courseID}", async (event) => {
const v_courseid = event.params.courseID;
console.log("v_courseid created: " + v_courseid);
return;
});
will only fire when a new document is created directly in the "course" collection. It will not fire for documents created in any other collection—even those with names like "partial_ingredients"—unless those documents exist in the "course" collection (for example, if they were created as subcollection documents but the trigger path was specified to monitor that nested location).
Possible Issues and Recommendations
-
Check Your Collection Names and Structure
• Verify that your Firestore structure is exactly as you expect. For example, if your courses are stored in "courses" (with an “s”) and not "course", then the trigger path should be changed accordingly.
• Also ensure that the partials are not being written in the same collection by mistake. If your partial documents live in, say, a subcollection (like "course/{courseID}/partial_ingredients/{docId}"), then they will not trigger a function listening on "course/{courseID}" because they are at a different path.
-
Avoiding Unintended Triggering
• If for some reason you are writing documents to the "course" collection that represent partial information (for example if you accidentally write both a full course document and a partial in the same collection), then add a filter inside your function to only process the valid course documents. For example:
exports.createAggrIngr = onDocumentCreated("course/{courseID}", async (event) => {
const v_courseid = event.params.courseID;
// For example, if partial documents follow a naming convention that you can detect...
if (v_courseid.startsWith("partial_")) {
console.log("Ignoring partial document: " + v_courseid);
return;
}
console.log("Course document created: " + v_courseid);
// Continue processing...
return;
});
• Alternatively, if partials belong in a completely different collection, consider using different trigger paths for them so that the function will not be invoked on those events.
-
Double‑Check Your Deployment
• Make sure there isn’t more than one function deployed that might be causing the same logs. Sometimes multiple triggers with overlapping patterns (or misnamed collections) can lead to unexpected logging.
Conclusion
In summary, the trigger path in your code should only listen to document creations in the "course" collection. If you're seeing events from "partial_ingredients," then check that:
- The collection name in your trigger precisely matches where your course documents are stored.
- The partial documents aren’t accidentally being written into the same collection.
- No additional or misconfigured triggers have been deployed.
Implementing an in‑function filter (if necessary) can also help ensure that only the intended events are further processed.
If after these checks the issue persists, please double‑check your Firestore structure and deployment configuration.