Hi guys, I am pulling data from firestore. When I ...
# getting-started
t
Hi guys, I am pulling data from firestore. When I need to sort these data by name or id numbers, do I need to pull them again from firestore or should I sort my list? When I look at a few places on the internet, it pulls from the firestore. Which is the right approach?
t
It's almost always better to request data from Firestore already sorted, especially if you are requesting a large collection or would like paginated results.
t
Hi @tseisel Thank you for answer, Yes, I can guess that, but why is it better to pull the data again in order instead of sorting the data that I have already pulled once?
t
If you already have fetched the unsorted data, it would be wasteful to request Firestore again just to sort the same data.
a
Why don't you just request the data once as sorted? The upside is that you don't have to waste the client device's resources doing any more processing on the fetched data.
t
@Advitiay Anand For example, in case he wants to sort by name, age, id number.
a
Right. It actually depends on how big the data is, and how costly it is to sort it. If you're building a small project then it does not matter. Just sort it on the device. However, if the data is quite large, then you should keep it sorted / filtered on the backend, and simply make paginated requests. Try to save the user from any possible lags.
t
I thought it was like that too Many tutorials on the Internet were pulled directly from the database. That’s why I wanted to confirm my opinion. Thanks for your answers.
đź‘Ť 1