Firebase Functions Triggers: Firestore, Auth, and Storage Essentials Quiz

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.

  1. Triggering on Firestore Document Creation

    Which event type would you use to trigger a function when a new document is added to a Firestore collection called 'orders'?

    1. onCreate
    2. onWrite
    3. onInsert
    4. onAdded

    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.

  2. Auth User Deletion Trigger

    What type of trigger activates a function when a user account is deleted from the authentication system?

    1. onUserDelete
    2. onRemove
    3. onAccountRemoved
    4. onDelete

    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.

  3. When to Use Storage Triggers

    If you want to automatically process an image after it is uploaded to cloud storage, which trigger should you use?

    1. onFinalize
    2. onSave
    3. onWrite
    4. onUploaded

    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.

  4. Detecting Firestore Document Updates

    Which event handler would run a function every time a document in the 'profiles' collection is updated?

    1. onEdit
    2. onPatch
    3. onUpdate
    4. onWrite

    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.

  5. Access to User Data in Auth Trigger

    When using an authentication trigger for new user sign-up, what user information is directly accessible in the triggered function?

    1. Billing information
    2. Display name, email, and user ID
    3. Session token only
    4. Username and password

    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.

  6. Responding to File Deletion in Storage

    Which trigger responds when a file is deleted from the storage bucket?

    1. onDestroy
    2. onRemoved
    3. onDelete
    4. onRemove

    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.

  7. Wildcards in Firestore Triggers

    What symbol is typically used as a wildcard within Firestore trigger paths to capture any document in a collection?

    1. [docId]
    2. {wildcard}
    3. {docId}
    4. u003CdocIdu003E

    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.

  8. Correct Placement for Function Logic

    Where should the main server-side logic be written when responding to Firestore, Auth, or Storage triggers?

    1. Inside the exported trigger function
    2. On the authentication sign-in page
    3. Directly within the Firestore rules
    4. In a client mobile app

    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.

  9. Event Parameter for Firestore onWrite

    What does the 'change' parameter contain in a Firestore onWrite trigger for the 'comments' collection?

    1. Both the before and after document snapshots
    2. Only the previous document snapshot
    3. The document ID only
    4. Only the new document data

    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.

  10. Idempotency in Triggered Functions

    Why is it important to make triggered functions idempotent when handling the same event more than once?

    1. To increase the function's speed
    2. To improve the syntax of trigger definitions
    3. To avoid repeated side effects and ensure consistent results
    4. To allow triggers to listen to multiple collections at 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.