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

查看:20
本文介绍了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(用户)列表的对象,所以我需要再调用 document.get() 大约 20 次,只是为了将用户作为对象而不是作为对他们的引用.

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 Reference 数据类型有什么用?

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

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