Explore core concepts of triggering cloud functions with Firestore, Authentication, and Storage events. This quiz helps reinforce your understanding of event-based automation and serverless workflows in cloud databases and user management.
Which event type would you use to trigger a function when a new document is added to a Firestore collection called 'orders'?
Explanation: The correct event for triggering a function when a new document is added is onCreate. This event specifically listens for when documents are newly created in a Firestore collection. Options like onInsert and onAdded are incorrect as they are not valid trigger methods. onWrite reacts to any write operation, including updates and deletes, making it less precise for just creation events.
What type of trigger activates a function when a user account is deleted from the authentication system?
Explanation: The onDelete trigger is used for events where a user account is deleted. This method listens specifically for user account deletions. The alternatives onUserDelete and onAccountRemoved are not valid trigger methods, and onRemove does not correspond to any user deletion event.
If you want to automatically process an image after it is uploaded to cloud storage, which trigger should you use?
Explanation: onFinalize triggers when a new file has been successfully written to storage, making it suitable for post-upload processing like image resizing. onUploaded and onSave may seem reasonable but are not actual methods. onWrite exists but triggers on both write and delete operations, making it less specific for new uploads.
Which event handler would run a function every time a document in the 'profiles' collection is updated?
Explanation: onUpdate specifically triggers when an existing document is modified, ensuring functions run only on updates. While onWrite will run on creation, update, and deletion, making it less precise. onEdit and onPatch are not valid trigger methods in this context.
When using an authentication trigger for new user sign-up, what user information is directly accessible in the triggered function?
Explanation: The triggered function receives basic user attributes like display name, email, and user ID at sign-up. Username and password are not provided for security reasons, and session tokens relate to authentication sessions rather than triggers. Billing information is unrelated and not accessible through auth triggers.
Which trigger responds when a file is deleted from the storage bucket?
Explanation: onDelete is the correct method for responding to file deletions within storage events. onRemoved and onRemove might sound similar but are not supported trigger options. onDestroy is not a valid option for this scenario.
What symbol is typically used as a wildcard within Firestore trigger paths to capture any document in a collection?
Explanation: The correct syntax uses curly braces, such as {docId}, to act as wildcards in Firestore trigger paths. {wildcard} is not a standardized term; u003CdocIdu003E and [docId] are incorrect syntax. Staying consistent with curly braces is necessary for correct event capture.
Where should the main server-side logic be written when responding to Firestore, Auth, or Storage triggers?
Explanation: All logic that responds to triggers should be implemented within the exported function itself for it to execute on the server side. Client apps and sign-in pages do not handle or receive trigger events, and security rules are not intended for server-side processing logic.
What does the 'change' parameter contain in a Firestore onWrite trigger for the 'comments' collection?
Explanation: The 'change' parameter provides both before and after snapshots, helping determine how the document was modified. Using only the previous snapshot or only the new data would limit access to change information. The document ID is part of the context but not the sole content of the 'change' parameter.
Why is it important to make triggered functions idempotent when handling the same event more than once?
Explanation: Idempotency ensures that re-running the same function does not create unintended duplicated side effects, which is critical in event-driven systems. It does not directly impact speed, syntax, or the ability to listen to multiple collections. Consistent results regardless of how many times the function runs is the key objective.