const animalsData = [];
let snapshot = null;
try {
if (!lastVisible) {
snapshot = await firestore()
.collection("animals")
.where("species", '==', selectedType)
.orderBy('timestamp', 'desc')
.limit(7)
.get();
} else {
snapshot = await firestore()
.collection("animals")
.where("species", '==', selectedType)
.orderBy('timestamp', 'desc')
.startAfter(lastDoc)
.limit(7)
.get();
}
The issue I'm encountering arises when applying the
condition to the query. Initially, the query functions correctly and returns the expected results. However, upon attempting to paginate the data (i.e., retrieving the next set of results), an empty array is returned even though there are additional documents that should match the specified criteria..where("species", '==', selectedType)
Additional details to consider:
The variable
selectedType
contains the species type for filtering purposes.Both
lastVisible
andlastDoc
play a role in tracking the last document in the current snapshot to facilitate fetching subsequent data sets.I have verified that the
selectedType
variable is consistently populated and accurate throughout the queries.Pagination functions flawlessly without the inclusion of the
.where
filter (i.e., retrieving all animals regardless of species).
The reason why the addition of the .where
filter leads to subsequent queries returning empty arrays remains unclear to me. Despite extensive research efforts, I have yet to identify a solution tailored to this specific challenge.
If you have any insights or recommendations on how to address this issue, your input would be greatly valued. Thank you!