How to retrieve the last document in a firebase collection. I would also like to get the document fields value

孤者浪人 提交于 2020-06-16 08:16:31

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!