Firestore:使用和不使用子收集数据来获取收集 [英] Firestore: Getting collection with and without its sub-collection data

查看:51
本文介绍了Firestore:使用和不使用子收集数据来获取收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 characters 的集合,其中每个文档都有一些公共数据,例如用户名和字符级别,还有一个私人子集合,其中包含诸如字符金等信息.

I have collection of charracters where each document has some public data like username and character level, but also a private sub collection that has things like that characters gold amount.

现在我可以查询特定文档的字符收集,但是不返回子收集数据,因此我需要执行辅助查询来检索它.

Right now I can query characters collection for a specific document, but sub-collection data is not returned, so I need to perform a secondary query to retrieve it.

这是实现这一目标的最佳方法吗?或者是否有一种方法可以表明我也想在第一个查询中接收子集合数据并将其合并在一起?

Is this the most optimal way to achieve this or is there a way to indicate that I also want to receive sub-collection data in the first query and sort of merge them together?

推荐答案

Firestore中的查询始终很浅.无法通过单个查询从多个不同的集合中获取文档.因此,如果您需要从两个集合中进行读取,则确实至少需要两次查询/读取操作.

Queries in Firestore are always shallow. There is no way to get documents from multiple different collection with a single query. So if you need to read from two collections, it will indeed at a minimum require two queries/read operations.

这篇关于Firestore:使用和不使用子收集数据来获取收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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