且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Firestore从集合中获取文档ID

更新时间:2023-02-14 09:23:54

我终于找到了解决方案.维克多(Victor)与文档数据保持密切联系.

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

const racesCollection: AngularFirestoreCollection<Race>;
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()不包含元数据,因此我们在需要文档ID时必须使用SnapshotChanges(),然后按照此处所述正确映射它

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