0
0
Firebasecloud~10 mins

Why write patterns affect consistency in Firebase - Test Your Understanding

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

Complete the code to write data to Firestore with strong consistency.

Firebase
db.collection('users').doc('user1').[1]({ name: 'Alice' })
Drag options to blanks, or click blank then click option'
Adelete
Bget
Cupdate
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' which only reads data.
Using 'delete' which removes data instead of writing.
2fill in blank
medium

Complete the code to perform a transaction that ensures atomic writes.

Firebase
db.runTransaction(async (transaction) => { const doc = await transaction.[1](docRef); /* update logic */ })
Drag options to blanks, or click blank then click option'
Aupdate
Bset
Cget
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'set' or 'update' before reading the document.
Using 'delete' which removes data instead of reading.
3fill in blank
hard

Fix the error in the code to ensure consistent writes with batch operations.

Firebase
const batch = db.batch(); batch.[1](docRef, { count: 1 }); await batch.commit();
Drag options to blanks, or click blank then click option'
Aset
Bget
Ccommit
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' which reads data instead of writing.
Calling 'commit' on the batch object instead of on the batch itself.
4fill in blank
hard

Fill both blanks to write data with merge option to avoid overwriting entire document.

Firebase
db.collection('users').doc('user2').[1]({ age: 30 }, { [2]: true })
Drag options to blanks, or click blank then click option'
Aset
Bupdate
Cmerge
Doverwrite
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' which does not accept merge option.
Using 'overwrite' which is not a valid option.
5fill in blank
hard

Fill all three blanks to perform a conditional update ensuring consistency.

Firebase
const doc = await db.collection('orders').doc('order1').get(); if (doc.exists && doc.data().status [1] 'pending') { await db.collection('orders').doc('order1').[2]({ status: 'completed' }, { [3]: true }); }
Drag options to blanks, or click blank then click option'
A===
Bset
Cmerge
D!==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' or '!==' incorrectly for the condition.
Using 'update' instead of 'set' with merge option.