-
Notifications
You must be signed in to change notification settings - Fork 978
Closed
Labels
Description
[REQUIRED] Describe your environment
- Operating System version: Ubuntu 20.04.4 LTS
- Browser version: 104.0 (64-bit) Mozilla Firefox for Ubuntu canonical - 1.0
- Firebase SDK version: firebase: 9.9.4
- Firebase Product: firestore
[REQUIRED] Describe the problem
Steps to reproduce:
I am not getting the link to add an index for the compound queries in my console. and instead, I am getting this error in the console
[2022-09-18T05:53:50.590Z] @firebase/firestore: Firestore (9.9.4): Uncaught Error in snapshot listener: {"code":"failed-precondition","name":"FirebaseError"}
After going through stackoverfollow I manually created the composite indexes in the firebase console under the firestore> indexes.
- index Descending, createdBy Descending
- index Descending, createdBy Arrays
for both indexes
- collection ID is
posts
- Query scope
collection
- status
enabled
When I remove the orderBy there is no error.
Relevant Code:
following
is an array with string values and the index
field has number as its value
ps: I am using react.
// TODO(you): code here to reproduce the problem
useEffect(()=>{
const q = query(
collection(db, "posts"),
orderBy("index", "desc"),
where("createdBy", "in", following)
);
const unsubscribe = onSnapshot(q, (querySnapshot) => {
const data = [];
querySnapshot.forEach((doc) => {
data.push(doc.data());
});
setPosts(data);
});
}, [])
DevYuns