javascript - OrderBy 时间戳 desc Firestore
问题描述
我目前正在使用firestore,我正在实施一项评论服务,客户可以在其中对课程进行评分和评论,我正在尝试按时间戳按降序检索评论,但快照是空的,但是当我按升序检索评论,快照带有结果。我过滤评论以匹配给定的课程,并确保评论不会因语言不好而被禁止。所以最后,我有一个这样的查询。
firestore
.collection("reviews")
.where("course", "==", this.course.id)
.where("censored", "==", false)
.orderBy("timestamp", "desc")
.startAfter(this.pagination)
.limit(5)
.get()
我正在查询的集合是评论集合,评论包含以下属性
{
// If a review was censored
censored: boolean,
// The comment of the review
comment: string,
// The score of the review from O to 5
score: number,
// The course uid that is being reviewed
course: string,
// The timestamp when the review was created
timestamp: timestamp, (time mark)
// The user that review the course
user: {
email: string,
name: string,
id: string,
}
}
我希望得到以降序排列的评论结果,以查看从最新到 oldesd 的评论。但是查询仅在以升序方式排序时才带有结果。查询中没有错误,仅带有empty: true
and size: 0
。
创建升序和降序索引。
上升指数
censored Ascendente course Ascendente timestamp Ascendente
降序索引
censored Ascendente course Ascendente timestamp Descendente
我已经通过更改.get
for a尝试了解决方案.onSnapshot
,但我没有工作。
解决方案
推荐阅读
- node.js - 如何使用启动参数(在无头模式下使用铬)提高 puppeteer 的性能?
- postgresql - 再次执行 PostgreSQL 查询的结果以获得最终结果集?
- python - 使用 Django 将日期选择器添加到现有的 html 表单
- css - React-rte 富文本编辑器更改按钮颜色
- recaptcha - 没有修改的 reCaptcha 问题
- python - 您正在尝试在没有默认值的情况下将不可为空的字段“post”添加到流中;我们不能那样做
- kotlin - 为什么 onClickListener 在我的片段活动中不起作用?
- solidity - 智能合约成功转账,但钱包里没有
- javascript - 使用百分比突出显示 Chartist 部分
- go - 如何安全地删除 Intellij 中所有文件上的结构字段的用法?