You run a Firestore query that filters on two fields and orders by a third. The required composite index is missing. What will Firestore do?
Think about how Firestore helps developers create missing indexes.
Firestore detects missing composite indexes needed for queries and returns an error with a direct link to create the index in the Firebase console.
Firestore requires composite indexes for queries that:
- Filter on multiple fields
- Order by fields not included in single-field indexes
- Use range filters on multiple fields
Which reason best explains why composite indexes are needed?
Think about how indexes help databases find data faster.
Composite indexes speed up queries by indexing multiple fields together, allowing Firestore to quickly find and sort matching documents.
Choose the valid JSON snippet for a composite index on 'status' ascending and 'createdAt' descending.
Check the exact property names and values Firestore expects in index definitions.
Firestore index JSON uses 'collectionGroup', 'queryScope', and 'fields' with 'fieldPath' and 'order' properties. The order values must be uppercase 'ASCENDING' or 'DESCENDING'.
You have several queries on a Firestore collection filtering and ordering by different combinations of fields. What is the best way to reduce the total composite indexes you must create?
Think about how composite indexes can cover multiple queries if designed carefully.
A single composite index covering all fields used in queries can serve multiple queries if the order of fields matches query requirements, reducing the total indexes needed.
Given a composite index on fields 'category' (ascending) and 'price' (descending), this query filters where category = 'books' and orders by price ascending. Why does it fail?
db.collection('products').where('category', '==', 'books').orderBy('price', 'asc')Check if the order directions in the query match the index definition.
Firestore requires the order directions in the query to match the composite index exactly. Here, the index orders 'price' descending but the query orders ascending, causing failure.