Cloud firestore not ordering problems when query

165 views Asked by At

My query it's not ordering. Actually it doesn't response. I receive an empty results screen when trying with this:

let stateQuery = firestore.collection('categories').where('user', '==', uid).orderBy('name'); 

        stateQuery.onSnapshot((querySnapshot) => {
          const docs = [];
          querySnapshot.forEach((doc) => { 
            docs.push({ ...doc.data(), id: doc.id });
          });
          setCategories(docs);
        });
      };

I tried also to do this, and nothing:

 let stateQuery = firestore.collection('categories').where('user', '==', uid);
 let stateQuery2 =  stateQuery.orderBy('name');
1

There are 1 answers

0
Gerry St.Pierre On BEST ANSWER

The issue is that your query requires a Composite index. Documentation on composite indexes is on this page.

Check the console for an error message which should include the link necessary to create the composite index. When I run a similar query on my database, I get this link

https://console.firebase.google.com/v1/r/project/(PROJECTNAME)/firestore/indexes?create_composite=Xd1.....XTY