0
0
Firebasecloud~10 mins

Batch limits and best practices 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 create a batch write in Firebase.

Firebase
const batch = db.[1]();
Drag options to blanks, or click blank then click option'
AwriteBatch
Bbatch
CstartBatch
DbeginBatch
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'startBatch' or 'beginBatch' which do not exist.
Using 'batch' directly without 'writeBatch()'.
2fill in blank
medium

Complete the code to commit the batch write.

Firebase
await batch.[1]();
Drag options to blanks, or click blank then click option'
Aapply
Bcommit
Csend
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'execute' or 'send' which are not Firebase batch methods.
Forgetting to await the commit.
3fill in blank
hard

Fix the error in the code to add a document write to the batch.

Firebase
batch.set(docRef, [1]);
Drag options to blanks, or click blank then click option'
Aname = 'Alice'
B['name', 'Alice']
C'name: Alice'
D{ name: 'Alice' }
Attempts:
3 left
💡 Hint
Common Mistakes
Passing data as a string or array instead of an object.
Using assignment syntax inside the data parameter.
4fill in blank
hard

Fill both blanks to limit batch size and handle errors.

Firebase
if (batchSize [1] MAX_BATCH_SIZE) {
  await batch.[2]();
  batch = db.writeBatch();
  batchSize = 0;
}
Drag options to blanks, or click blank then click option'
A>=
Bcommit
C<=
Dexecute
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '>=' for the size check.
Using 'execute()' which is not a Firebase batch method.
5fill in blank
hard

Fill all three blanks to create a safe batch write loop.

Firebase
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();
Drag options to blanks, or click blank then click option'
Aset
B+=
C>=
Dupdate
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'update' instead of 'set' which may fail if document does not exist.
Using '=' instead of '+=' to increment batchSize.
Using '<=' instead of '>=' in the batch size check.