如何解决按timestamp 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,}
}
我期望得到的评论以降序排列,以查看从最新到旧的评论。但是,查询仅在按升序排序时才带有结果。查询中没有错误,只有empty: true
和size: 0
附带。
创建升序和降序索引。
上升索引
censored Ascendente course Ascendente timestamp Ascendente
降序索引
censored Ascendente course Ascendente timestamp Descendente
我已经尝试通过将.get
更改为.onSnapshot
来解决问题,但是我没有用。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。