Complete the code to create a batch write in Firebase.
const batch = db.[1]();In Firebase, writeBatch() is used to create a batch write object.
Complete the code to commit the batch write.
await batch.[1]();The commit() method sends all the writes in the batch to the database.
Fix the error in the code to add a document write to the batch.
batch.set(docRef, [1]);The data must be an object with key-value pairs, like { name: 'Alice' }.
Fill both blanks to limit batch size and handle errors.
if (batchSize [1] MAX_BATCH_SIZE) { await batch.[2](); batch = db.writeBatch(); batchSize = 0; }
Check if batch size is greater or equal to max, then commit the batch.
Fill all three blanks to create a safe batch write loop.
for (const item of items) { const docRef = db.collection('users').doc(item.id); batch.[1](docRef, item.data); batchSize [2] 1; if (batchSize [3] MAX_BATCH_SIZE) { await batch.commit(); batch = db.writeBatch(); batchSize = 0; } } await batch.commit();
Use set to add writes, increment batchSize with +=, and check if batchSize is greater or equal to max.
