Skip to content

URL Index Creation: __name__ field is not sorted in the same direction of the last sorted field in the index definition #9097

Open
@glumb

Description

@glumb

Operating System

not applicable

Environment (if applicable)

not applicable

Firebase SDK Version

11.8.1

Firebase SDK Product(s)

Firestore

Project Tooling

doesnt matter but we use Webpack 5.98.0

Detailed Problem Description

According to https://firebase.google.com/docs/firestore/query-data/index-overview :

By default, the name field is sorted in the same direction of the last sorted field in the index definition

however, if I run this query:

import { getFirestore, collection, query, where, orderBy, limit, getDocs } from "firebase/firestore";

const db = getFirestore();

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

const querySnapshot = await getDocs(q);
querySnapshot.forEach(doc => {
  console.log(doc.id, doc.data());
});

firebase gives me a link to create this index:

Image

Where __name__ is not sorted according to the last field in the index, which would be _meta.dateCreated:DESCENDING but sorted ASCENDING for unknown reason.

Why is this? By what rules is this sorting determined? We need to create the indexes programatically and therefore need to know what index is required.

Steps and code to reproduce issue

  1. compose a query with a where-in+orderBy and orderBy instruction (on different field)
  2. execute the query
  3. click on the query create link
  4. see that fierbase suggests name beeing sorted not according to the last index field

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions