Firestore Getting documents id from collection

后端 未结 9 1161
陌清茗
陌清茗 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条回答
  •  暖寄归人
    2020-11-30 00:47

    For document references, not collections, you need:

    // when you know the 'id'
    
    this.afs.doc(`items/${id}`)
      .snapshotChanges().pipe(
        map((doc: any) => {
          const data = doc.payload.data();
          const id = doc.payload.id;
          return { id, ...data };
        });
    

    as .valueChanges({ idField: 'id'}); will not work here. I assume it was not implemented since generally you search for a document by the id...

提交回复
热议问题