0
0
GCPcloud~20 mins

Firestore document model in GCP - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Firestore Document Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Firestore Document Structure

Which statement correctly describes a Firestore document?

AA document is a collection of documents and cannot contain key-value pairs.
BA document is a flat list of values without keys and cannot contain nested collections.
CA document is a single string value stored in Firestore without any keys.
DA document is a collection of key-value pairs and can contain nested collections.
Attempts:
2 left
💡 Hint

Think about how data is organized inside Firestore documents.

Architecture
intermediate
2:00remaining
Firestore Collection and Document Relationship

Given a Firestore database, which option correctly describes the relationship between collections and documents?

ACollections contain documents, and documents can contain subcollections.
BDocuments contain collections, and collections can contain subdocuments.
CCollections contain only other collections, not documents.
DDocuments contain only key-value pairs and cannot contain collections.
Attempts:
2 left
💡 Hint

Consider how Firestore organizes data hierarchically.

Configuration
advanced
2:00remaining
Firestore Document Data Types

Which Firestore document data type is not supported directly?

ATimestamp
BArray
CFunction
DGeoPoint
Attempts:
2 left
💡 Hint

Think about what kinds of data Firestore stores versus what it executes.

security
advanced
2:00remaining
Firestore Document Access Control

Which Firestore security rule correctly restricts read access to documents in the 'users' collection only to the authenticated user with matching user ID?

GCP
service cloud.firestore {
  match /databases/{database}/documents {
    match /users/{userId} {
      allow read: if request.auth.uid == userId;
    }
  }
}
Arequest.auth.uid == userId
Brequest.auth.token.email_verified == true
Crequest.auth.uid != userId
Drequest.time < timestamp.date(2025, 1, 1)
Attempts:
2 left
💡 Hint

Think about how to match the authenticated user's ID with the document ID.

service_behavior
expert
3:00remaining
Firestore Document Write Behavior with Transactions

Consider this Firestore transaction code snippet:

const docRef = firestore.collection('counters').doc('counter1');
await firestore.runTransaction(async (transaction) => {
  const doc = await transaction.get(docRef);
  const newCount = (doc.data()?.count ?? 0) + 1;
  transaction.update(docRef, { count: newCount });
});

What is the expected behavior if two clients run this transaction simultaneously?

ABoth transactions will overwrite each other, resulting in only one increment.
BOne transaction will fail due to a conflict and retry automatically, ensuring correct count increment.
CBoth transactions will increment the count correctly without overwriting each other.
DThe transaction will cause a syntax error and not run.
Attempts:
2 left
💡 Hint

Think about how Firestore transactions handle concurrent writes.