Complete the code to write data to Firestore with strong consistency.
db.collection('users').doc('user1').[1]({ name: 'Alice' })
Using set writes data and ensures the document is created or overwritten, which affects consistency by making the latest data available.
Complete the code to perform a transaction that ensures atomic writes.
db.runTransaction(async (transaction) => { const doc = await transaction.[1](docRef); /* update logic */ })Within a transaction, get reads the document to ensure the transaction works with the latest data, maintaining consistency.
Fix the error in the code to ensure consistent writes with batch operations.
const batch = db.batch(); batch.[1](docRef, { count: 1 }); await batch.commit();
In batch writes, set is used to write data to a document. Using 'get' or 'commit' here is incorrect.
Fill both blanks to write data with merge option to avoid overwriting entire document.
db.collection('users').doc('user2').[1]({ age: 30 }, { [2]: true })
Using set with the merge option updates only specified fields, preserving other data and improving consistency.
Fill all three blanks to perform a conditional update ensuring consistency.
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 }); }
The code checks if the status is exactly 'pending' using ===, then uses set with merge to update the status without overwriting other fields, maintaining consistency.