I want to navigate through the next and previous post of my firestore collection. I have setup next post function. But I can't make the previous function.
Here is my next post query:
firestore()
.collection('Posts')
.orderBy(firestore.FieldPath.documentId())
.startAfter(this.state.currentDoc)
.limit(1)
But sadly, firestore doesn't work with .orderBy(firestore.FieldPath.documentId(), 'desc')
I tried with:
firestore()
.collection('Posts')
.orderBy(firestore.FieldPath.documentId())
.limit(1)
It goes to the very first document of the collection. Adding ascending order doesn't work here again.
Let me know if any further information is needed.
EDIT:
According to the answer, here is what I am trying, instead of id, I am using time of the post when it was created. The time format is like: 1625511322000
firestore()
.collection('Posts')
.orderBy('time', 'desc')
.startAfter(this.state.currentDoc)
.limit(1)