access data from document referenced inside firestore collection

我只是一个虾纸丫 提交于 2019-12-11 08:48:42

问题


I have a collection inside firestore database that consists of several data fields and references. Structure looks like this:

firstCollection document sample

{
  name: 'parent',
  //more fields,
  second: //reference to document from second collection
}

secondCollection referenced document sample

{
   title: 'document title',
   more: 3456,
   etc: '...'
}

I have angular application with angularfire2 library included. In one of my html files I need to print data from the first collection including some field values from document of the second collection. Document from the second collection has valid reference from the first collection (see above). This is what I want to do:

<div *ngFor="let first of firstCollection | async">

  this works - {{first.name}}

  Now the question is, How can I access document data from the second collection here? 
  What I need is something like the following:

  {{first.second.title}} - this doen't work because 'second' is just reference

</div>

回答1:


Reading data from Cloud Firestore is shallow. This means when you read the first document, you have not yet loaded any of the data in the second document (to which you have a reference).

You'll have to perform another get() or listen operation on that reference in order to get the data. https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md



来源:https://stackoverflow.com/questions/46663160/access-data-from-document-referenced-inside-firestore-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!