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 ?
My error:
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)
This is my code:
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;
});
});
}
Go ahead and follow that link to create the necessary database index. You will need a composite of uid + the startedAt field.
I'm facing the same issue, but when I click the link, it not creat by it self. Just open the firebase console index, but nothing happens..
I have exactly the same issue of @Flip32
@NoNameAB I'm still stucked. If you resolve this, pls help me.
@Flip32 I solved it, I just created an index manually and it worked fine.
@NoNameAB So I tried, but I just get orderBy wrong. I mean, I want to put the newest first, but I got de last first.
this is what I tried:
this.afs.collection
.where('validado', '==', true).orderBy('data'));
And in Firebase I created putting "tipo" ascending, "validado" ascending, "data" ascending.
I tried put "data" descending, but I got an error.
@Flip32 because there is an error in your code, the function orderBy takes 2 parameters so you must do : .orderBy('data', 'desc')
@NoNameAB That's it man! Tnks
Most helpful comment
Go ahead and follow that link to create the necessary database index. You will need a composite of uid + the startedAt field.