I am storing Ideas posted by the application in Firestore. The data is stored in Firestore like this Ideas/{documentID}/IdeaObject. The issue is when I retr
You cannot use a String (timeStamp
) when querying your database instead of a Date (date
) and expect to behave as it was a date. So to solve this, please change the following line of code:
firestoreDb.collection("ideas")
.orderBy("timeStamp", Query.Direction.ASCENDING)
to
firestoreDb.collection("ideas")
.orderBy("date", Query.Direction.ASCENDING)
You have to also add index in your firebase account which is in database -> Indexes -> add index
In my case, the vanilla version would be,
firestoreDb.collection("ideas")
.orderBy("timestamp", "asc")
firestoreDb.collection("ideas")
.orderBy("timestamp", "desc")
"ideas" is the name of your collection
"timestamp" is the key or field or column name to be used for sorting.
"asc" or "desc" is the option to be used for the order