Firestore Getting documents id from collection

后端 未结 9 1155
陌清茗
陌清茗 2020-11-30 00:16

I\'m trying to retrieve my documents with id but can\'t figure it out.
Currently I retrieve my documents like this :

const racesCollection: AngularFir         


        
9条回答
  •  萌比男神i
    2020-11-30 01:10

    I've finally found the solution. Victor was close with the doc data.

    const racesCollection: AngularFirestoreCollection;
    return racesCollection.snapshotChanges().map(actions => {       
      return actions.map(a => {
        const data = a.payload.doc.data() as Race;
        data.id = a.payload.doc.id;
        return 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

提交回复
热议问题