javascript - 如何在 .where 之后访问 firestore 中的子集合
问题描述
我有一个集合和一个名称数组,集合可以通过 id 直接查询
我想根据名称访问唯一的子集合,并且我想在之后返回子集合
查询的结构是这样的
firestore
.collection
.where("name", '==', inputName)
.collection('subCollection')
.get()
这似乎不起作用,是否有替代方法
解决方案
Firestore 查询只能检查它们返回的文档中的数据。无法从子集合中返回文档,也无法从父文档中筛选字段。
常见的解决方案是将 也添加name
到子集合中的每个文档(例如作为名为 的字段parentName
),然后对名为 的所有集合执行集合组查询subCollection
:
firestore
.collectionGroup('subCollection')
.where("parentName", '==', inputName)
.get()
推荐阅读
- sql - 引用列的数量必须与引用的列匹配
- java - Java Graphics2D drawString 正在“涂黑”源图像
- go - 如何从 github 获取 go-socket.io 以在 Go 中使用
- tsql - 如何根据另一种列类型对同一列进行不同的求和
- flutter - 我如何控制头像大小和它与FilterChip中的标签之间的间距
- progressive-web-apps - PWA - Chrome Add-To-Home-screen 添加为 WebAPK 但不添加到主屏幕
- javascript - 如何合并属性 JavaScript 对象
- ios13 - UIDocumentPickerViewController iOS13 不工作
- java - 是否可以使用 jsch 在 jsp 上打开 SSH 控制台?
- vb.net - 单击时道奇专注于表单