集合组查询是否从所有具有相同名称的集合中获取数据? [英] Does collection group queries get data from all collections with the same name?

查看:59
本文介绍了集合组查询是否从所有具有相同名称的集合中获取数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下Firebase Cloud Firestore模式:

I have this Firebase Cloud Firestore schema:

my_db -> users -> uid -> places -> placeId

my_db -> places -> placeId

此收集组查询是否会在两个路径中都获得位置?如果是,请确保我得到副本.有什么办法可以避免这种情况吗?

Will this collection group queries get places within both path? If yes, for sure I get duplicates. Is there any way I can avoid that?

我的目标是获取数据库中所有用户的所有位置,而不是所有集合中的所有位置.

My goal is to get all places within all users and not all places within all collections in my database.

推荐答案

集合组查询始终查看具有所有名称和名称的任何路径的 all 顶级集合和子集合.无法更改此行为.如果要限制查询的范围,则需要使用不同的名称命名集合.

Collection group queries always look at all top-level collections and subcollections with any path at any depth with the name you provide. There is no way to change this behavior. You will need to name your collections differently if you want to limit the scope of the query.

如果您无法更改数据库结构,则可以通过查看客户端快照中的文档路径来过滤客户端上的文档,从而至少忽略不感兴趣的集合的结果,并自行决定是否应该处理该文档.

If you can't change your database structure, you could at least ignore the results from the collections you're not interested in by filtering the documents on the client by looking at the path of the document in the snapshots you receive, and deciding for yourself if you should process that document.

另一种策略是将一个布尔字段放在顶级集合文档中不存在的每个子集合的文档中.您可以使用此字段仅查询子集合中的文档.

Another strategy would be to put a boolean field in the documents of each one of your subcollections that does not exist in the top-level collection documents. You can use this field to query only for only the documents in the subcollections.

这篇关于集合组查询是否从所有具有相同名称的集合中获取数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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