Bird
Raised Fist0
Fluttermobile~20 mins

Cloud Firestore CRUD in Flutter - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Firestore CRUD Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ ui_behavior
intermediate
2: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});
AThe document with ID 'users' is overwritten with the new data.
BA new document with an auto-generated ID is created in the 'users' collection with fields 'name' and 'age'.
CAn error occurs because the document ID is missing.
DNo document is created because 'add' only updates existing documents.
Attempts:
2 left
💡 Hint
Remember that 'add' creates a new document with a random ID.
📝 Syntax
intermediate
1: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});
Aupdate
Bset
Cadd
Dcreate
Attempts:
2 left
💡 Hint
Use the method that modifies existing fields without overwriting the whole document.
❓ lifecycle
advanced
2: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}');
});
AThe listener prints the document count only once when the app starts.
BThe listener prints the document count only when a new document is added, not when updated or deleted.
CThe listener causes an error because snapshots() returns a Future, not a Stream.
DThe listener prints the current number of documents every time the 'users' collection changes in Firestore.
Attempts:
2 left
💡 Hint
Streams update on any change in the collection including add, update, or delete.
🔧 Debug
advanced
2: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();
AThe doc() method is called without an ID, so it targets a non-existing document.
BThe delete() method requires a callback function to confirm deletion.
CThe collection name 'users' is invalid and causes the error.
DThe code is correct and should not cause any error.
Attempts:
2 left
💡 Hint
Deleting requires specifying the exact document ID.
🧠 Conceptual
expert
2:30remaining
Firestore Offline Persistence Behavior
Which statement best describes Firestore offline persistence in a Flutter app?
AFirestore does not support offline data; all reads and writes require internet connection.
BFirestore requires manual syncing of data after reconnecting to the internet.
CFirestore caches data locally and syncs changes automatically when the device reconnects to the internet.
DFirestore deletes local data cache every time the app restarts.
Attempts:
2 left
💡 Hint
Think about how apps work when you lose internet but still see data.

Practice

(1/5)
1.

What does CRUD stand for in Cloud Firestore operations?

easy
A. Connect, Refresh, Upload, Delete
B. Copy, Run, Undo, Download
C. Create, Read, Update, Delete
D. Create, Remove, Update, Download

Solution

  1. Step 1: Understand CRUD acronym meaning

    CRUD is a common term in databases meaning the four basic operations on data.
  2. Step 2: Match each letter to the correct operation

    C = Create, R = Read, U = Update, D = Delete are the standard meanings.
  3. Final Answer:

    Create, Read, Update, Delete -> Option C
  4. Quick Check:

    CRUD = Create, Read, Update, Delete [OK]
Hint: Remember CRUD as basic data actions: create, read, update, delete [OK]
Common Mistakes:
  • Confusing CRUD letters with unrelated words
  • Mixing up 'Remove' with 'Delete'
  • Thinking CRUD includes 'Download'
2.

Which Flutter code snippet correctly adds a new document to a Firestore collection named users?

FirebaseFirestore.instance.collection('users').____({'name': 'Alice'});
easy
A. update
B. add
C. delete
D. get

Solution

  1. Step 1: Identify method to add new document

    The add method creates a new document with given data in the collection.
  2. Step 2: Confirm other methods' purposes

    update modifies existing documents, delete removes documents, get reads data.
  3. Final Answer:

    add -> Option B
  4. Quick Check:

    Adding new document uses add() [OK]
Hint: Use add() to create new documents in a collection [OK]
Common Mistakes:
  • Using update() to add new documents
  • Confusing get() with add()
  • Trying to delete() when adding data
3.

What will be the output of this Flutter Firestore code snippet?

var doc = await FirebaseFirestore.instance.collection('tasks').doc('task1').get();
print(doc.exists);

Assuming the document task1 exists in the tasks collection.

medium
A. true
B. false
C. null
D. Throws an error

Solution

  1. Step 1: Understand doc.get() behavior

    The get() method fetches the document snapshot from Firestore.
  2. Step 2: Check the exists property

    If the document exists, doc.exists returns true; otherwise false.
  3. Final Answer:

    true -> Option A
  4. Quick Check:

    Document exists property = true [OK]
Hint: doc.exists is true if document is found in Firestore [OK]
Common Mistakes:
  • Assuming doc.exists returns document data
  • Expecting false even if document exists
  • Not awaiting the get() call
4.

Identify the error in this Flutter Firestore update code:

FirebaseFirestore.instance.collection('users').doc('user1').update({'age': 30});

Assuming the document user1 does not exist.

medium
A. No error, update creates document if missing
B. Update silently fails without error
C. Syntax error in update method call
D. Throws an error because document does not exist

Solution

  1. Step 1: Understand update() behavior on missing document

    The update() method requires the document to exist; otherwise, it throws an error.
  2. Step 2: Confirm no syntax errors

    The syntax is correct, so error is due to missing document.
  3. Final Answer:

    Throws an error because document does not exist -> Option D
  4. Quick Check:

    update() fails if document missing [OK]
Hint: update() needs existing document; else error occurs [OK]
Common Mistakes:
  • Thinking update() creates new documents
  • Confusing update() with set()
  • Ignoring async/await for update()
5.

You want to delete a Firestore document only if it exists to avoid errors. Which Flutter code snippet correctly does this?

var docRef = FirebaseFirestore.instance.collection('orders').doc('order1');
// What code to safely delete?
hard
A. docRef.get().then((doc) { if (doc.exists) docRef.delete(); });
B. docRef.delete();
C. docRef.update({'deleted': true});
D. docRef.set(null);

Solution

  1. Step 1: Check document existence before deleting

    Use get() to fetch the document snapshot and check exists.
  2. Step 2: Call delete() only if document exists

    This avoids errors from deleting non-existing documents.
  3. Final Answer:

    docRef.get().then((doc) { if (doc.exists) docRef.delete(); }); -> Option A
  4. Quick Check:

    Check exists before delete to avoid errors [OK]
Hint: Always check doc.exists before delete() to prevent errors [OK]
Common Mistakes:
  • Calling delete() without checking existence
  • Using update() to delete documents
  • Setting document to null instead of deleting
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard