0
0
Firebasecloud~5 mins

Firestore trigger functions in Firebase - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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) =&gt; {<br>  const newData = snap.data();<br>  // your code here<br>});</code>
Click to reveal answer
Which Firestore trigger runs when a document is deleted?
AonRemove
BonUpdate
ConCreate
DonDelete
In an onUpdate trigger, how do you get the new data?
Achange.before.data()
Bchange.after.data()
Csnap.data()
Dcontext.data()
What does the placeholder {userId} represent in the document path 'users/{userId}'?
AA variable document ID
BA field name
CA collection name
DA fixed document ID
Why are Firestore trigger functions considered secure?
AThey run on the server and can't be bypassed by users
BThey run on the client device
CThey require user permission every time
DThey only run once
Which event type would you use to send a welcome email when a new user document is created?
AonUpdate
BonDelete
ConCreate
DonWrite
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.