android - 如何为音乐应用创建 Firestore 架构?
问题描述
我有一个用于音乐的 Cloud Firestore 数据库:
ROOT
|
+-- shops {collection}
|
+-- countryName {document}
|
+-- cityName {collection}
|
+-- shopIdOne {document}
|
+-- dvds {collection}
|
+-- dvdIdOne {document}
| |
| +-- name: "Led Zeppelin: Live in Seattle 1977"
|
+-- dvdIdTwo {document}
|
+-- name: "Queen: Live at AID 1985"
使用此模式,我可以从现有城市的商店中获取所有音乐 dvd,这很好。问题是同一张dvd可以存在于不同城市的至少5家商店。
我知道我不能查询多个集合,所以问题是,如何创建一个模式,以便我可以通过 dvd 名称查询数据库并获取它存在的所有商店?
解决方案
更新:截至 2019 年 5 月,Cloud Firestore 现在支持集合组查询。
使用集合组查询,您可以查询dvds
所有商店的所有集合:
db.collectionGroup('dvds').where('name', '==', 'Led Zeppelin: Live in Seattle 1977')
原始答案
如果您希望能够找到具有特定 DVD 的商店,您还必须将准确的信息存储在数据库中。所以:
ROOT
|
+-- DVDs {collection}
|
+-- dvdIdOne {document}
| |
| +-- name: "Led Zeppelin: Live in Seattle 1977"
| |
| +-- shops {collection}
| |
| +-- shopIdOne {document}
|
+-- dvdIdTwo {document}
|
+-- name: "Queen: Live at AID 1985" |
|
+-- shops {collection}
|
+-- shopIdOne {document}
要么,要么您可以等待集合组查询变得可用(虽然目前尚无时间表),然后查看是否允许当前数据结构上的用例。
推荐阅读
- python - Python - 如何在 HTML 中查找所有具有模式的子字符串?
- vtk - 将 VtkVolume 保存为 stl 文件(3d 数据)?
- javascript - 从 React 类导出函数
- javascript - 如何将本地 javascript 添加到 vue 组件?
- c# - BackgroundWorker 在方法正在执行时显示进度
- java - 无法使用 ProjectExecutionServices 创建 TaskExecuter 类型的服务
- python - 将 xmltodict 模块导入 Visual Studio 代码
- linux - 系统负载是多少
- javascript - 如何仅在每个输入的数字后添加逗号
- javascript - 如何将半字节字符转换为全字节字符日语