Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to use the orderBy() function from firestore using getDocs?

I am currently trying to this (doesn't actually orderBy anything)

let articlesSnapshot = await getDocs(articlesRef, orderBy('timestamp'));

In the documentation they only show this use case using queries rather than getDocs... Is there a way around this?

like image 631
Bilal Abraham Avatar asked Sep 01 '25 22:09

Bilal Abraham


1 Answers

The trick is to create a query like this:

let articlesSnapshot = await getDocs(query(articlesRef, orderBy('timestamp')));
like image 58
Frank van Puffelen Avatar answered Sep 03 '25 11:09

Frank van Puffelen