问题
How to retrieve the last document from a Cloud Firestore collection? I would also like to get the document fields value.
Here this the image below:
回答1:
How to retrieve the last document in a firebase collection?
To solve this, you need to use a query that should look like this:
FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
Query query = rootRef.collection("High Volume")
.orderBy("Time", Query.Direction.DESCENDING)
.limit(1);
query.get().addOnCompleteListener(/* ... */);
This query will order the results according to the time property and will limit the results to one.
来源:https://stackoverflow.com/questions/52362292/how-to-retrieve-the-last-document-in-a-firebase-collection-i-would-also-like-to