Reputation: 5
I wanna compare and find the latest date among all the chat documents. Then get the message and date field from the latest one and display it. May I know is there a way to do this?
Upvotes: 0
Views: 65
Reputation: 598765
You're looking for a query that is ordered by descending date
and then limiting it to one result.
So something like:
Query query = collectionRef.orderBy("date", Direction.DESCENDING).limit(1);
Then you can just read the data once or attach a listener to also get updates.
Upvotes: 4