从Firestore集合内引用的文档访问数据 [英] access data from document referenced inside firestore collection

查看:47
本文介绍了从Firestore集合内引用的文档访问数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firestore数据库中有一个集合,该集合由几个数据字段和引用组成.结构如下:

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

firstCollection文档示例

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

secondCollection引用的文档样本

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

我有包含angularfire2库的angular应用程序.在我的一个html文件中,我需要打印第一个集合的数据,包括第二个集合的文档中的某些字段值.来自第二个集合的文档具有来自第一个集合的有效参考(请参见上文).这就是我想做的:

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>

推荐答案

从Cloud Firestore读取数据很浅.这意味着,当您阅读第一个文档时,您尚未在第二个文档中加载任何数据(您已对其进行引用).

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).

您必须执行另一个get()或对该引用进行监听操作才能获取数据. https://github.com/angular/angularfire2/blob/master/docs/firestore/documents.md

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

这篇关于从Firestore集合内引用的文档访问数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆