Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a batch write instance.
Firebase
const batch = [1](db); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'batchWrite()' instead of 'writeBatch()'.
Trying to call 'batch()' directly on the database.
✗ Incorrect
The writeBatch() method creates a new batch write instance in Firebase.
2fill in blank
mediumComplete the code to add a set operation to the batch.
Firebase
batch.[1](docRef, { name: 'Alice' });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'add()' which is for collections, not batch writes.
Using 'update()' which requires the document to exist.
✗ Incorrect
The set() method adds a set operation to the batch to write data to a document.
3fill in blank
hardFix the error in the code to commit the batch.
Firebase
await batch.[1](); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'execute()' which does not exist on batch.
Using 'commitBatch()' which is not a method.
✗ Incorrect
The commit() method sends all the batch operations to Firestore.
4fill in blank
hardFill both blanks to add a delete operation and then commit the batch.
Firebase
batch.[1](docRef); await batch.[2]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remove()' which is not a batch method.
Using 'execute()' instead of 'commit()'.
✗ Incorrect
Use delete() to add a delete operation and commit() to send the batch.
5fill in blank
hardFill all three blanks to update a document, add a set operation, and commit the batch.
Firebase
batch.[1](docRef, { age: 30 }); batch.[2](docRef2, { name: 'Bob' }); await batch.[3]();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'write()' which is not a batch method.
Mixing up 'set()' and 'update()' methods.
✗ Incorrect
Use update() to change fields, set() to write data, and commit() to send the batch.