Error in query cursors
https://firebase.google.com/docs/firestore/query-data/query-cursors#use_a_document_snapshot_to_define_the_query_cursor
wrong
db.collection("cities").doc("SF").get().then(
(documentSnapshot) {
final biggerThanSf = db
.collection("cities")
.orderBy("population")
.startAt([documentSnapshot]);
},
onError: (e) => print("Error: $e"),
);
correct
.startAtDocument(documentSnapshot)
same issue
https://firebase.google.com/docs/firestore/query-data/query-cursors#paginate_a_query // Construct query for first 25 cities, ordered by population
final first = db.collection("cities").orderBy("population").limit(25);
first.get().then(
(documentSnapshots) {
// Get the last visible document
final lastVisible = documentSnapshots.docs[documentSnapshots.size - 1];
// Construct a new query starting at this document,
// get the next 25 cities.
final next = db
.collection("cities")
.orderBy("population")
.startAfter([lastVisible]).limit(25);
// Use the query for pagination
// ...
},
onError: (e) => print("Error completing: $e"),
);
correct way:
if(documentSnapshots.docs.isNotEmpty){
.
.
.
.
.startAfterDocument(lastVisible).limit(25);
}
I think either method should be acceptable, but I'll label for further insight from the team.
cc @Lyokone
Using document snapshot like .startAt([documentSnapshot]) cause this error
Error: Invalid argument (dartObject): Could not convert: Instance of '_JsonDocumentSnapshot'
dart-sdk/lib/internal/js_dev_runtime/private/ddc_runtime/errors.dart 266:49 throw
packages/firebase_core_web/src/interop/utils/utils.dart 95:5 jsify
packages/cloud_firestore_web/src/interop/utils/utils.dart 42:23 jsify
dart-sdk/lib/internal/iterable.dart 415:31 elementAt
dart-sdk/lib/internal/iterable.dart 344:26 moveNext
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 781:20 next
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 600:14 of
dart-sdk/lib/internal/iterable.dart 214:7 toList
packages/cloud_firestore_web/src/interop/firestore.dart 487:22 [_createQueryConstraint]
packages/cloud_firestore_web/src/interop/firestore.dart 461:11 startAfter
packages/cloud_firestore_web/src/query_web.dart 80:20 [_buildWebQueryWithParameters]
packages/cloud_firestore_web/src/query_web.dart 152:46
The documentation has been updated to reflect the above mentioned changes 👍