【发布时间】:2021-07-10 07:31:20
【问题描述】:
我想浏览我的 firestore 收藏的下一篇和上一篇文章。我已经设置了下一个帖子功能。但是我不能做之前的功能。
这是我的下一个帖子查询:
firestore()
.collection('Posts')
.orderBy(firestore.FieldPath.documentId())
.startAfter(this.state.currentDoc)
.limit(1)
但遗憾的是,firestore 不适用于 .orderBy(firestore.FieldPath.documentId(), 'desc')
我试过了:
firestore()
.collection('Posts')
.orderBy(firestore.FieldPath.documentId())
.limit(1)
它转到集合的第一个文档。在这里添加升序不再起作用。
如果需要任何进一步的信息,请告诉我。
编辑:
根据答案,这是我正在尝试的,而不是 id,我使用的是帖子创建时的时间。时间格式如:1625511322000
firestore()
.collection('Posts')
.orderBy('time', 'desc')
.startAfter(this.state.currentDoc)
.limit(1)
【问题讨论】:
标签: javascript reactjs firebase google-cloud-firestore