Which statement correctly describes a Firestore document?
Think about how data is organized inside Firestore documents.
Firestore documents store data as key-value pairs and can include nested collections, allowing hierarchical data organization.
Given a Firestore database, which option correctly describes the relationship between collections and documents?
Consider how Firestore organizes data hierarchically.
In Firestore, collections hold documents, and documents can have nested subcollections, allowing multi-level data structures.
Which Firestore document data type is not supported directly?
Think about what kinds of data Firestore stores versus what it executes.
Firestore supports data types like Timestamp, Array, and GeoPoint, but it does not support storing executable functions as document fields.
Which Firestore security rule correctly restricts read access to documents in the 'users' collection only to the authenticated user with matching user ID?
service cloud.firestore {
match /databases/{database}/documents {
match /users/{userId} {
allow read: if request.auth.uid == userId;
}
}
}Think about how to match the authenticated user's ID with the document ID.
The rule allows read access only if the authenticated user's ID matches the document ID, ensuring users can only read their own data.
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?
Think about how Firestore transactions handle concurrent writes.
Firestore transactions detect conflicts and retry automatically, so one transaction will retry if a conflict occurs, ensuring the count increments correctly.