Firestore索引错误 [英] Firestore index error

查看:82
本文介绍了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天全站免登陆