This error occurs when your Firestore query combines filters and sorting in a way that requires a composite index. Learn how to create the missing index using the Firebase console, CLI, or by following the automatic error link.
The "Missing index for this query" error in Firebase Firestore occurs when you attempt a compound query—one that combines `where()` clauses with `orderBy()` on multiple fields—without the required composite index. Firestore automatically creates single-field indexes, but composite indexes (needed when filtering AND sorting by different fields) must be created manually. Firestore prevents these queries from running without an index to ensure query performance and consistency across your database.
When you encounter the missing index error, Firestore (usually) provides a direct link in the error message or Firebase console. The error will look like:
FirebaseError: PERMISSION_DENIED: Missing index for this query
[cloud_firestore/failed-precondition]If a link is present in the error message, click it to automatically navigate to the Firebase console with the required index configuration pre-filled.
If no link appears, manually create the index:
1. Go to the Firebase Console (https://console.firebase.google.com)
2. Select your project
3. Navigate to Firestore Database
4. Click the "Indexes" tab
5. Click "Create Index"
6. Enter the collection name (e.g., "users")
7. Add the fields used in your query (both filters and orderBy fields)
8. Set the sort direction (Ascending/Descending) for each field
9. Click "Create Index"
Firestore will begin building the index, which may take a few minutes depending on your data size.
For production and IaC (Infrastructure as Code), deploy indexes via CLI:
# Initialize Firestore in your project
firebase init firestore
# This creates a firestore.indexes.json file
# Edit it to include your custom composite indexes:
{
"indexes": [
{
"collectionGroup": "users",
"queryScope": "COLLECTION",
"fields": [
{ "fieldPath": "status", "order": "ASCENDING" },
{ "fieldPath": "createdAt", "order": "DESCENDING" }
]
}
],
"fieldOverrides": []
}
# Deploy the indexes
firebase deploy --only firestore:indexesWait for the index to complete building before testing your query:
1. In the Firestore Console, go to Indexes tab
2. Look for your index in the "Composite Indexes" section
3. Wait for the status to change from "Building" to "Enabled" (green checkmark)
4. Once enabled, your query will execute successfully
Check your browser console for confirmation:
document.addEventListener('firestore-index-ready', (e) => {
console.log('Index is ready:', e.detail);
// Now safe to run your complex queries
});Once the index is built, test that your query now works:
import { collection, query, where, orderBy, getDocs } from 'firebase/firestore';
const q = query(
collection(db, 'users'),
where('status', '==', 'active'),
orderBy('createdAt', 'desc')
);
const snapshot = await getDocs(q);
console.log('Query successful! Documents:', snapshot.docs.length);If the query still fails, verify:
- Index status is "Enabled" (not "Building")
- Query fields exactly match the index fields
- Field ordering in your query matches the index configuration
For collection-group queries across multiple collections, you need a collection-group index rather than a single-collection index. Collection-group indexes must be created manually. Vector indexes (for semantic search) cannot be created in the console—use the provided gcloud CLI command instead. Firestore automatically creates single-field indexes for all non-array and non-map fields, plus array-contains indexes for array fields, so simple single-field queries never require manual index creation. Note that indexes count against your Firestore pricing, so monitor your index count in the console. For large collections, index creation can take several minutes. You can check index build progress in the Indexes tab. If you delete an index and recreate the query immediately, Firestore may report the index is still building even though it's no longer in the list—in this case, wait 5-10 minutes before retrying.
messaging/UNSPECIFIED_ERROR: No additional information available
How to fix "messaging/UNSPECIFIED_ERROR: No additional information available" in Firebase Cloud Messaging
App Check: reCAPTCHA Score Too Low
App Check reCAPTCHA Score Too Low
storage/invalid-url: Invalid URL format for Cloud Storage reference
How to fix invalid URL format in Firebase Cloud Storage
auth/missing-uid: User ID identifier required
How to fix "auth/missing-uid: User ID identifier required" in Firebase
auth/invalid-argument: Invalid parameter passed to method
How to fix "auth/invalid-argument: Invalid parameter passed to method" in Firebase