Skip to content

Instantly share code, notes, and snippets.

@ankurg22
Last active January 19, 2022 06:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ankurg22/c709417ea0bb4cf21ae3a434091c9d74 to your computer and use it in GitHub Desktop.
Save ankurg22/c709417ea0bb4cf21ae3a434091c9d74 to your computer and use it in GitHub Desktop.
// 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