I am using a where clause on my firestore query to filter based on an attribute type and then ordering them using the orderBy to order them by time.
const tradesRef = firebase
.firestore()
.collection("cex-trades")
.orderBy("time", "desc")
.limit(16);
useEffect(() => {
if (filter === "5m") {
tradesRef
.where("type", "==", "fifteenMinutes")
.get()
.then((collections) => {
const tradesData = collections.docs.map((trade) => trade.data());
const lastDoc = collections.docs[collections.docs.length - 1];
const firstDoc = collections.docs[collections.docs.length - 16];
setTrades(tradesData);
setFirstTrade(firstDoc);
setLastTrades(lastDoc);
})
.catch((error) => {
console.error(error);
});
}
}, [filter]);
When I run my code, I am getting this error:
FirebaseError: The query requires an index. You can create it here: https://console.firebase.google.com/v1/r/project/whaletracer-432e8/firestore/indexes?create_composite=ClRwcm9qZWN0cy93aGFsZXRyYWNlci00MzJlOC9kYXRhYmFzZXMvKGRlZmF1bHQpL2NvbGxlY3Rpb25Hcm91cHMvY2V4LXRyYWRlcy9pbmRleGVzL18QARoICgR0eXBlEAEaCAoEdGltZRACGgwKCF9fbmFtZV9fEAI
I followed the link and created an index as followed:

After creating the index, I am still getting the same error. Any idea how to solve the issue?