0
0
Firebasecloud~10 mins

Server timestamps in Firebase - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a Firestore field to the server timestamp.

Firebase
docRef.set({ createdAt: [1] })
Drag options to blanks, or click blank then click option'
ATimestamp.now()
BDate.now()
Cnew Date()
Dfirebase.firestore.FieldValue.serverTimestamp()
Attempts:
3 left
💡 Hint
Common Mistakes
Using client time like Date.now() instead of server timestamp.
Using new Date() which is client-side time.
2fill in blank
medium

Complete the code to update a Firestore document's 'updatedAt' field with the server timestamp.

Firebase
docRef.update({ updatedAt: [1] })
Drag options to blanks, or click blank then click option'
ATimestamp.now()
Bfirebase.firestore.FieldValue.serverTimestamp()
Cnew Date()
DDate.now()
Attempts:
3 left
💡 Hint
Common Mistakes
Using client-side date functions instead of server timestamp.
Confusing update with set method.
3fill in blank
hard

Fix the error in the code to correctly set a Firestore field to the server timestamp.

Firebase
docRef.set({ time: [1] })
Drag options to blanks, or click blank then click option'
Afirebase.firestore.FieldValue.serverTimestamp()
Bfirebase.firestore.Timestamp.now()
Cnew Date()
DDate.now()
Attempts:
3 left
💡 Hint
Common Mistakes
Using Timestamp.now() which is client time.
Using new Date() or Date.now() which are client times.
4fill in blank
hard

Fill both blanks to create a Firestore document with 'createdAt' and 'updatedAt' fields set to server timestamps.

Firebase
docRef.set({ createdAt: [1], updatedAt: [2] })
Drag options to blanks, or click blank then click option'
Afirebase.firestore.FieldValue.serverTimestamp()
Bnew Date()
CDate.now()
Dfirebase.firestore.Timestamp.now()
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing client-side and server-side timestamp methods.
Using different methods for createdAt and updatedAt.
5fill in blank
hard

Fill all three blanks to update a Firestore document with 'lastLogin', 'lastLogout', and 'lastAction' fields set to server timestamps.

Firebase
docRef.update({ lastLogin: [1], lastLogout: [2], lastAction: [3] })
Drag options to blanks, or click blank then click option'
Anew Date()
Bfirebase.firestore.FieldValue.serverTimestamp()
DDate.now()
Attempts:
3 left
💡 Hint
Common Mistakes
Using client-side date functions.
Using inconsistent timestamp methods across fields.