【发布时间】:2018-01-22 17:05:27
【问题描述】:
在我的网站中,我正在进行一项类似tests 的调查,每个测试都有attendies 子集合看起来像这样
当有人完成测试时,我还将他们的 uid 添加到 completed 字段,就像我在框中绘制的那样。现在我想根据status == completed查询tests。
这是我尝试过的
this.completedModulesRef$ = this.afs.collection('tests', ref =>
ref.orderBy('moduleNum', 'desc')
.where('completed.'+auth.uid+'.status','==','completed'));
this.completedModules$ = this.completedModulesRef$.valueChanges();
然后firestore要求我添加索引,当我按照生成的链接添加索引时,我得到了这个
指向completed.CurrentUserId.status。我相信这仅适用于当前用户。
我有几个问题
1) .where('completed.'+auth.uid+'.status','==','completed') 这是一个有效的查询吗?
2) 如果是,我该如何索引它?
3) 有什么方法可以根据子集合值查询顶级集合? (这是我真正想要的)
任何帮助表示赞赏。
【问题讨论】:
-
我只能回答数字 3,我知道这在 atm 是不可能的。我对另外两个也很好奇。
-
@DarkNeuron 这对我来说是一个糟糕的数据库模式。我将整个完成的对象作为一个集合移动到
users/uid/tests/tesId,因此当用户完成测试时,它将在他的目录下找到。 -
也许您可以使用 GraphQL 查询来实现这一点?
标签: javascript firebase angularfire2 google-cloud-firestore