【发布时间】:2019-09-20 14:04:37
【问题描述】:
我的 Firestore 文档中有一个布尔字段。我想按布尔值订购集合。 answer boolean true 的文档应该出现在 answer boolean false 的文档之前。
const item: AngularFirestoreCollection<any> =
this.afs.collection(`items`,
(ref) => ref.where('questionId', '==', questionId)
.orderBy('updatedAt', 'desc')
.orderBy('answer'));
return item.valueChanges();
firestore 中的项目按以下顺序排列
items = {[
{
id: 1,
questionId: x1,
answer: false,
updatedAt: 848939
},
{
id: 2,
questionId: x2,
answer: false,
updatedAt: 848936
},
{
id: 3,
questionId: x3,
answer: true,
updatedAt: 848938
}
]}
查询完成后,我希望第三个项目位于索引 0...结果中的第一个项目。现在我得到的只是orderBy updatedAt。
上面的查询没有给我上面要求的结果。 如何进行这样的查询?
【问题讨论】:
-
请将您的数据库结构添加为截图。
-
您确定第二次订购不会改变第一次订购的结果吗?请编辑问题以显示您的源数据以及您希望查询结果中的排序方式。
-
@DougStevenson 。我编辑了这个问题。谢谢
标签: javascript firebase google-cloud-firestore angularfire