Firestore 索引错误 [英] Firestore index error

查看:26
本文介绍了Firestore 索引错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am facing some problem when use angular 2 to query data from Firestore.

谁能帮我检查一下,告诉我哪里做错了?

Could anyone please help me by checking it and tell me where I have done wrong ?

我的错误:

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)

这是我的代码:

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

推荐答案

发生此错误是因为默认情况下 Firestore 不需要为仅使用等式子句的查询附加索引,因此这不是您的案例.

This error is happening because by default Firestore does not require additional indexes for queries that only use equality clauses, therefore that is not your case.

要使您的查询正常工作,您只需点击错误消息的链接并在 Firebase 控制台中为您的查询创建一个新索引.

To make your query work you only need to click on the link of the error message and create a new index for your query in the Firebase Console.

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

To get to know more about how Firestore indexes work you can read on the documentation.

这篇关于Firestore 索引错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆