Firebase Firestore,在另一个文档中获取参考文档 [英] Firebase Firestore, get the reference document inside another document

查看:76
本文介绍了Firebase Firestore,在另一个文档中获取参考文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Firebase Cloud Firestore,当我要获取包含参考字段的文档时,希望将参考字段作为文档接收,而不是作为对文档的引用...

I'm using Firebase Cloud Firestore, I want when I'm getting a document with reference field inside to receive the reference field as a document and not as a reference to the document...

我有一个用户集合和一个班级集合(在学校),每个班级都包含一个用户参考列表(该班级的学生). 当我使用document.get()(以通过其引用获取类)时,它返回一个包含(用户)DocumentReference列表的对象,因此,我需要再调用20次以上的document.get()才能使用户获得对象,而不是对其的引用.

I have a collection of users and collection of classes (at school) and each class contains a list of references to users (the students in this class). When I using document.get() (to get the class by its reference) it returns an object that contains a list of DocumentReference (of the users) so I need to call document.get() around 20 more times just to get the users as objects and not as a reference to them.

我希望能够调用document.get()一次,它将把所有引用带入文档中,如下所示: 数据库代码

I want to be able to call document.get() once and it will bring me all the references as documents, like that: database and code

是否有一种优雅的方法?

Is there an elegant way to do this?

推荐答案

您无法指示Firestore客户端SDK在获取单个文档期间自动遵循文档引用.您必须要求每个单独的文件.换句话说,没有SQL中可能期望的联接"操作.

You can't instruct the Firestore client SDK to automatically follow document references during a fetch of a single document. You have to request each individual document. In other words, there is no "join" operation like you might expect in SQL.

另请参见: firestore参考数据类型有什么用?/a>

See also: What is firestore Reference data type good for?

这篇关于Firebase Firestore,在另一个文档中获取参考文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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