Consider a Firestore database with multiple subcollections named comments under different posts. Which documents will this query return?
const query = firestore.collectionGroup('comments').where('approved', '==', true);const query = firestore.collectionGroup('comments').where('approved', '==', true);
Think about what collectionGroup does: it searches all subcollections with the given name, regardless of their parent.
The collectionGroup('comments') query searches all subcollections named 'comments' anywhere in the database. The where clause filters documents where 'approved' is true. So it returns all approved comments from all posts.
Which option contains the correct syntax for querying all documents in subcollections named reviews where the rating is greater than 4?
firestore.collectionGroup('reviews').where('rating', '>', 4).get()
Check the syntax of the where method parameters carefully.
The where method requires three parameters: field name, comparison operator as a string, and value. Option B uses the correct syntax. Options A, C, and D have syntax errors or invalid operators.
You want to query all orders subcollections for documents where status is 'shipped' and total is greater than 100. Which approach optimizes performance best?
Think about how Firestore uses indexes to speed up queries with multiple filters.
Firestore performs best when queries use indexed fields. Combining filters in one query with a composite index is efficient. Running multiple queries or filtering client-side is slower and uses more bandwidth.
This query fails with an error about a missing index:
firestore.collectionGroup('messages').where('sender', '==', 'alice').where('read', '==', false).get()What is the cause?
Check Firestore's indexing requirements for collection group queries with multiple filters.
When a collection group query uses multiple filters, Firestore requires a composite index on those fields. Without it, the query fails with a missing index error.
Which of the following is a true limitation when using collection group queries?
Think about Firestore's indexing rules and how they affect ordering in queries.
Firestore requires that any orderBy field in a collection group query must be indexed and usually must be included in the where filters or have a composite index. This is a common limitation that requires creating indexes.