I add some data to the collection. When i retrive it, it is sorted by that generated id. Is it posible to make firebase to sort it in chronological order or it is required to add one more field with date and sort it once it is retrived in flutter?
Yes you need a createdAt
timestamp field and use it like
Firestore.instance
.collection("users")
.orderBy('createdAt', descending: true or false).getDocuments()
And you can store createdAt
on flutter side with Timestamp
(Its included in cloud_firestore
), and you can get current timestamp with Timestamp.now()
There is no built-in metadata on when a document was inserted. If you want to order the documents by insertion order, you will indeed have to add a field with that information yourself and order on that field when retrieving the documents.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With