如何检索 firebase 集合中的最后一个文档.我还想获取文档字段值 [英] How to retrieve the last document in a firebase collection. I would also like to get the document fields value

查看:17
本文介绍了如何检索 firebase 集合中的最后一个文档.我还想获取文档字段值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 Cloud Firestore 集合中检索最后一个文档?我还想获取文档字段值.

How to retrieve the last document from a Cloud Firestore collection? I would also like to get the document fields value.

这是下图:

推荐答案

如何检索 firebase 集合中的最后一个文档?

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(/* ... */);

此查询将根据 time 属性对结果进行排序,并将结果限制为一个.

This query will order the results according to the time property and will limit the results to one.

这篇关于如何检索 firebase 集合中的最后一个文档.我还想获取文档字段值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆