Skip to content

__name__ beeing stripped from firestore:indexes cmd #8758

Closed as duplicate

Description

@glumb

Why it matters
The issue is that some queries require a non standard __name__ sorting, like

const query = await db.collection("Auditlog")
  .where("tenantID", "in", ["IeZfE0yKWs0kGBl1IG5M"])
  .orderBy("_meta.dateCreated", "desc")
  .limit(50)
  .get();

wants me to create this index (maybe this is another bug? as I read that the name shall automatically sort according to the last sort in the index)

Image

When I now create this index online in the firebase console, download the indexes via the client and redeploy them to another project, the __name__ sorting information got lost, as its now creating an index sorting by DESCENDING for __name__

[REQUIRED] Environment info

firebase-tools: 14.7.0

Platform: macOS

[REQUIRED] Test case

just call firebase firestore:indexes. the __name__ field is stripped

[REQUIRED] Steps to reproduce

  1. have an index in firestore
  2. call firebase firestore:indexes.
  3. the __name__ field is stripped

[REQUIRED] Expected behavior

__name__ is present

[REQUIRED] Actual behavior

the __name__ field is stripped due to

// Ignore any fields that point at the document ID, as those are implied
// in all indexes.
const fields = index.fields.filter((field: types.IndexField) => {
return field.fieldPath !== "__name__";
});

Activity

  1. added 2 commits that reference this issue on Jun 15, 2025
    1946c12
    7101425
  2. aalej commented on Jun 20, 2025

    @aalej
    Contributor

    Hey @glumb, thanks for the detailed report and for opening up a PR for this! Let me know if I may be wrong here, but I looked around other repositories and I think the code snippet you're using is something like:

    const query = await db.collection("Auditlog")
               .where("tenantID", "in", ["IeZfE0yKWs0kGBl1IG5M"])
               .orderBy("_meta.dateCreated", "desc")
               .orderBy('tenantID', 'asc')
               .limit(50)
               .get();

    Which is similar to the code you provided in firebase/firebase-js-sdk#9097.

    I was able to reproduce the issue using the code snippet you provided in the JS SDK repository. The generated index looks like

    Image

    Running firebase firestore:indexes outputs

    {
      "indexes": [
        {
          "collectionGroup": "Auditlog",
          "queryScope": "COLLECTION",
          "fields": [
            {
              "fieldPath": "tenantID",
              "order": "ASCENDING"
            },
            {
              "fieldPath": "_meta.dateCreated",
              "order": "DESCENDING"
            }
          ]
        }
      ],
      "fieldOverrides": []
    }

    Then deploying this to a different project outputs a different index
    Image

    Looking at some of the issue we have, I think we can mark this as a duplicate of #7629. Could you link the PR you filed to that issue instead?

    I'm closing this one as a duplicate, but please let me know if you think this is a different issue and needs to be reopened.

  3. added a commit that references this issue on Jul 15, 2025
    cbb8582
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions