let's say I have 3 collection 'col1' , 'col2' & 'col3' each collection consists of thousands of documents i want to push all the documents data into a single array of object according to their timestamp in a descending order. The firestore orderBy command can be used only for single collection So is there any way i can push the data from firestore in such a way that the array comes sorted by default ?
2 Answers
1
votes
0
votes
The most effecient approach would be to merge sorted results. Time complexity in your case will be O(n) since you have constant number of arrays.
Here is an interesting post with the explanation of the algorithm if you are interested. Otherwise, just use lodash.merge then sort it. Time complexity will remain O(n) since sorting is O(log(n)). It won't really matter unless you have millions of entries in your collections.