Firestore索引错误

Tri*_*yen 4 firebase angular google-cloud-firestore

当使用angular 2从Firestore查询数据时,我遇到了一些问题.

有人可以帮我检查一下,告诉我哪里做错了吗?

我的错误:

ERROR Error: The query requires an index. You can create it here: https://console.firebase.google.com/project/admin-e8a7b/database/firestore/indexes?create_index=EgR0ZW1wGgcKA3VpZBACGg0KCXN0YXJ0ZWRBdBADGgwKCF9fbmFtZV9fEAM
at new FirestoreError (vendor.bundle.js:19925)
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

getTemp(uid): Observable<any> {
let temps = [];
var today = new Date();
return this.afs.collection<Temps>('temp', ref => ref.where('uid', '==', uid).orderBy('startedAt', 'desc')).snapshotChanges()
  .map(actions => {
    return actions.map(action => {
      const data = action.payload.doc.data() as Temps;
      console.log(data.temp);
      return data.temp;
    });
  });
}
Run Code Online (Sandbox Code Playgroud)

Mat*_*lva 11

发生此错误是因为默认情况下,Firestore不需要对仅使用相等子句的查询使用其他索引,因此情况并非如此.

要使查询起作用,您只需单击错误消息的链接,然后在Firebase控制台中为查询创建新索引.

要了解有关Firestore索引如何工作的更多信息,您可以阅读文档.

  • 这一定是答案。 (2认同)