How to fix PERMISSION_DENIED: Missing index for this query in Firebase

FirebaseBEGINNERMEDIUMUpdated Dec 22, 2025· 124 views

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.

Quick fix

Fixes PERMISSION_DENIED: Missing index for this query

FirebaseError: PERMISSION_DENIED: Missing index for this query
[cloud_firestore/failed-precondition]
  1. Look for the automatic index creation link in the error
  2. Create the index in the Firebase Console manually
  3. Deploy indexes using Firebase CLI
  4. Verify the index is ready before running queries
firebase — error
FirebaseError: PERMISSION_DENIED: Missing index for this query
[cloud_firestore/failed-precondition]
PERMISSION_DENIED: Missing index for this query

What this error means

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.

Typical symptoms

  • Query fails with PERMISSION_DENIED error mentioning a missing index
  • Firestore console displays "The query requires an index" error message
  • Simple queries work, but complex queries with multiple where() and orderBy() clauses fail
  • Error message includes a clickable link to create the index
  • App stops working after adding sorting to an existing filtered query

Common causes

  1. Query uses multiple where() clauses combined with orderBy() on different fields
  2. Range comparison (<, <=, >, >=) used with orderBy() on a different field
  3. Collection-group queries that require specific field ordering
  4. Complex queries with multiple inequality filters
  5. orderBy() applied after filtering on a field not included in the filter

How to fix "PERMISSION_DENIED: Missing index for this query"

1Look for the automatic index creation link in the error

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:

bash
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.

2Create the index in the Firebase Console manually

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.

3Deploy indexes using Firebase CLI

For production and IaC (Infrastructure as Code), deploy indexes via CLI:

bash
# 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:indexes
4Verify the index is ready before running queries

Wait 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:

javascript
document.addEventListener('firestore-index-ready', (e) => {
  console.log('Index is ready:', e.detail);
  // Now safe to run your complex queries
});
5Test your query after index creation

Once the index is built, test that your query now works:

javascript
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

Advanced notes

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.

Frequently asked questions

What does "PERMISSION_DENIED: Missing index for this query" mean?
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.
How do I fix "PERMISSION_DENIED: Missing index for this query"?
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.
What causes "PERMISSION_DENIED: Missing index for this query"?
Query uses multiple where() clauses combined with orderBy() on different fields Range comparison (<, <=, >, >=) used with orderBy() on a different field Collection-group queries that require specific field ordering
Is the "PERMISSION_DENIED: Missing index for this query" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading