0

我的查询不是订购。实际上它没有反应。尝试此操作时,我收到一个空的结果屏幕:

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);
        });
      };

我也尝试过这样做,但没有:

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

1 回答 1

0

问题是您的查询需要复合索引。有关复合索引的文档在此页面上

检查控制台是否有错误消息,其中应包含创建复合索引所需的链接。当我在我的数据库上运行类似的查询时,我得到了这个链接

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

于 2020-09-15T19:39:25.617 回答