Challenge - 5 Problems
Firestore CRUD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate2:00remaining
Firestore Document Creation Behavior
What will be the result on Firestore after running this Flutter code snippet to add a new document?
Flutter
FirebaseFirestore.instance.collection('users').add({'name': 'Alice', 'age': 30});
Attempts:
2 left
💡 Hint
Remember that 'add' creates a new document with a random ID.
✗ Incorrect
The 'add' method creates a new document with a unique ID inside the specified collection. It does not overwrite or require an ID.
📝 Syntax
intermediate1:30remaining
Correct Firestore Document Update Syntax
Which option correctly updates the 'age' field of a Firestore document with ID 'user123' in the 'users' collection?
Flutter
FirebaseFirestore.instance.collection('users').doc('user123').???({'age': 31});
Attempts:
2 left
💡 Hint
Use the method that modifies existing fields without overwriting the whole document.
✗ Incorrect
'update' changes only specified fields in an existing document. 'set' replaces the whole document unless merge is true.
❓ lifecycle
advanced2:00remaining
Firestore Stream Listener Behavior
What happens in the Flutter app when using this Firestore stream to listen to 'users' collection changes?
Flutter
FirebaseFirestore.instance.collection('users').snapshots().listen((snapshot) { print('Documents count: ${snapshot.docs.length}'); });
Attempts:
2 left
💡 Hint
Streams update on any change in the collection including add, update, or delete.
✗ Incorrect
The snapshots() method returns a stream that emits a new snapshot whenever the collection changes in any way.
🔧 Debug
advanced2:00remaining
Fix Firestore Document Deletion Error
This Flutter code tries to delete a Firestore document but will not work as expected. What is the cause?
Flutter
FirebaseFirestore.instance.collection('users').doc().delete();Attempts:
2 left
💡 Hint
Deleting requires specifying the exact document ID.
✗ Incorrect
Calling doc() without an ID creates a reference to a document with a random ID that does not exist, so delete() targets the wrong document.
🧠 Conceptual
expert2:30remaining
Firestore Offline Persistence Behavior
Which statement best describes Firestore offline persistence in a Flutter app?
Attempts:
2 left
💡 Hint
Think about how apps work when you lose internet but still see data.
✗ Incorrect
Firestore enables offline persistence by caching data locally and syncing changes automatically once online.