Reputation: 803
I am have almost this structure of data in my firestore and
I am fetching data using two queries orderBy
and where
but there two are not working and giving me error
the piece of code i am using is this
useEffect(() => {
db.collection("accounts")
.doc("[email protected]")
.collection("glasses")
.where("stock", ">", 0)
.orderBy("id", "desc")
.onSnapshot((snapshot) =>
setGlasses(snapshot.docs.map((doc) => doc.data()))
);
}, []);
if i use only single query orderBy() or where() then the query works but the combination of there query dont work together.
Solution of the problem i want is to get the data whose stock is greater then zero
and also order the data according to id
Upvotes: 0
Views: 791
Reputation: 26171
You need to use .orderBy("stock").orderBy("id", "desc")
to fix that query.
However this won't give the results you want. Instead you'll need to add a boolean field "hasStock"
that has the same meaning as what you are querying.
Upvotes: 1