Recall & Review
beginner
What is a Firestore trigger function?
A Firestore trigger function is a special cloud function that runs automatically when data changes in a Firestore database, like when a document is created, updated, or deleted.
Click to reveal answer
beginner
Name the three main Firestore trigger event types.
The three main Firestore trigger event types are: <br>1. onCreate - runs when a new document is added.<br>2. onUpdate - runs when an existing document is changed.<br>3. onDelete - runs when a document is removed.
Click to reveal answer
intermediate
How do you access the changed data in an onUpdate Firestore trigger?
In an onUpdate trigger, you get two snapshots: before and after. Use
change.before.data() to see old data and change.after.data() to see new data.Click to reveal answer
intermediate
Why use Firestore trigger functions instead of client-side code?
Trigger functions run on the server, so they are secure and reliable. They can enforce rules, update other data, or send notifications without depending on the user's device or app.
Click to reveal answer
beginner
What is the syntax to create a Firestore onCreate trigger for a collection named 'users'?
Use: <br><code>exports.userCreated = functions.firestore.document('users/{userId}').onCreate((snap, context) => {<br> const newData = snap.data();<br> // your code here<br>});</code>Click to reveal answer
Which Firestore trigger runs when a document is deleted?
✗ Incorrect
The onDelete trigger runs when a document is removed from Firestore.
In an onUpdate trigger, how do you get the new data?
✗ Incorrect
change.after.data() gives the updated document data after the change.
What does the placeholder {userId} represent in the document path 'users/{userId}'?
✗ Incorrect
The {userId} is a variable that matches any document ID in the 'users' collection.
Why are Firestore trigger functions considered secure?
✗ Incorrect
Trigger functions run on the server, so users cannot bypass or alter them.
Which event type would you use to send a welcome email when a new user document is created?
✗ Incorrect
onCreate triggers run when a new document is added, perfect for sending welcome emails.
Explain how Firestore trigger functions work and give an example of when you might use one.
Think about what happens when data changes in your app and how triggers can help.
You got /3 concepts.
Describe the difference between onCreate and onUpdate triggers in Firestore.
Focus on when each trigger activates and what data you get.
You got /3 concepts.