Skip to content

Fix: firestore.indexes.json missing indexes and wrong sort order cause query errors on fresh setup #113

@matteosantolin

Description

@matteosantolin

Bug

Fresh deployments fail with FirebaseError: The query requires an index on multiple pages (Dashboard, Cashflow, Patrimonio) due to three issues in firestore.indexes.json.

Issues found

1. monthly-snapshots — wrong sort order

The index defines year and month as DESCENDING, but snapshotService.ts queries with orderBy('year', 'asc'), orderBy('month', 'asc'). Firestore treats these as different indexes and refuses to serve the query.

2. expenses — index missing

expenseService.ts queries expenses filtered by userId and ordered by date DESCENDING, but no corresponding composite index exists in the file.

3. expenseCategories — index missing

expenseCategoryService.ts queries expenseCategories filtered by userId and ordered by name ASCENDING, but no corresponding composite index exists in the file.

Fix

{
  "indexes": [
    {
      "collectionGroup": "monthly-snapshots",
      "queryScope": "COLLECTION",
      "fields": [
        { "fieldPath": "userId", "order": "ASCENDING" },
        { "fieldPath": "year", "order": "ASCENDING" },
        { "fieldPath": "month", "order": "ASCENDING" }
      ]
    },
    {
      "collectionGroup": "expenses",
      "queryScope": "COLLECTION",
      "fields": [
        { "fieldPath": "userId", "order": "ASCENDING" },
        { "fieldPath": "date", "order": "DESCENDING" }
      ]
    },
    {
      "collectionGroup": "expenseCategories",
      "queryScope": "COLLECTION",
      "fields": [
        { "fieldPath": "userId", "order": "ASCENDING" },
        { "fieldPath": "name", "order": "ASCENDING" }
      ]
    }
  ]
}

Steps to reproduce

  1. Clone the repo and follow the setup guide
  2. Run firebase deploy --only firestore:indexes
  3. Open the app — Dashboard, Cashflow and Patrimonio pages show query index errors in the browser console

Environment

Discovered on a fresh Firebase project (europe-west1) following the official SETUP.md.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions