const querySnapshot = await getDocs(collection(db, "posts"));
Need to order querySnapshot by ‘eventdate’ and in ‘desc’ order.
const querySnapshot = await getDocs(collection(db, "posts", orderBy('eventDate', 'desc')))
Have attempted to implement this way but no success, the entries on firebase just stopped loading.
2
Answers
Most likely you’re missing a composite index that is needed for the query (ascending and descending order are different indexes).
To troubleshoot and fix this:
Let start data as current time and compare it with your time field as i did
, then orderBy it in desc formate as you needed
it is Firebase FireStore-Cloud Excercise which i was performed some days back
but if you are using firebase RealtimeDataBase Then just syntax will change otherthan logic will same.