-
Notifications
You must be signed in to change notification settings - Fork 991
Open
Description
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:
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
- compose a query with a where-in+orderBy and orderBy instruction (on different field)
- execute the query
- click on the query create link
- see that fierbase suggests name beeing sorted not according to the last index field
