Skip to content

Instantly share code, notes, and snippets.

@ankurg22
Last active Jan 19, 2022
Embed
What would you like to do?
// To observe new records being added.
firestoreDb.collection(collectionPath)
.orderBy("created_at", Direction.ASCENDING)
.startAfter(currentTimestamp)
.addSnapshotListener(...)
// To observe last N records
firestoreDb.collection(collectionPath)
.orderBy("created_at", Direction.ASCENDING)
.endBefore(currentTimestamp)
.limitToLast(10) // N = 10
.addSnapshotListener(...)
// To observe last N to 2N records
firestoreDb.collection(collectionPath)
.orderBy("created_at", Direction.ASCENDING)
.endBefore(lastRecordTimestamp)
.limitToLast(10) // N = 10
.addSnapshotListener(...)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment