I'm trying to retrieve my documents with id but can't figure it out.
Currently I retrieve my documents like this :
const racesCollection: AngularFirestoreCollection<Races> = this.afs.collection('races');
return racesCollection.valueChanges();
I do get my documents list perfectly, however there is no doc id with them.
How can I retrieve it for each document ?
I've finally found the solution. Victor was close with the doc data.
ValueChanges() doesn't include metadata, therefor we must use SnapshotChanges() when we require the document id and then map it properly as stated here https://github.com/angular/angularfire2/blob/master/docs/firestore/collections.md
Since you are using angularFire, it doesn't make any sense if you are going back to default firebase methods for your implementation. AngularFire itself has the proper mechanisms implemented. Just have to use it.
valueChanges()
method of angularFire provides an overload for getting the ID of each document of the collection by simply adding a object as a parameter to the method.Here 'idField' must be same as it is. 'id' can be anything that you want your document IDs to be called.
Then the each document object on the returned array will look like this.
Then you can easily get the document ID by referencing to the field that you named.
AngularFire 5.2.0