I am trying to return data from firestore database sorted by id. After updating one entry data is returned with one record out of sort. After updating a second entry to confirm issue data is again returned now with two records out of sort. Id is a number on the db and so should be in numeric order.
Here is the code:
Future getKegIds() async {
await FirebaseFirestore.instance.collection("kegs").orderBy("id", descending: false ).get().then(
(snapshot) => snapshot.docs.forEach(
(document) {
print(document.reference);
kegIds.add(document.reference.id);
},
),
);
}
and here are the results:
Kegs 15 and 16 are out of order.
I think is something like orderBy(FieldPath.documentId)
, orderBy('id')
is order by a field in document call id
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.