java - Firebase Firestore 集合的最大值

标签 java android firebase google-cloud-platform google-cloud-firestore

collection
        *
        Random_Id1
                *amount:100
                *name:John
        Random_Id2
                *amount:150
                *name:Matt
        Random_Id3
                *amount:65
                *name:Alice

我有一个 firestore 集合,其中包含不同的文档。这些文件中有数据(姓名、年龄、金额等)。有没有办法可以返回集合中的最高或最大金额?我正在java(android)中实现这个。 在上述结构的情况下,最大值将为 150。 预先感谢您

最佳答案

您必须使用通过 orderBy()limit() 组合定义的查询,如下所示:

CollectionReference collectionRef = db.collection("collection");
Query query = collectionRef.orderBy("amount", descending: true).limit(1);

请参阅此处的文档 https://firebase.google.com/docs/firestore/query-data/queries在这里https://firebase.google.com/docs/firestore/query-data/order-limit-data

关于java - Firebase Firestore 集合的最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52953145/

相关文章:

java - 谁能帮我写一个更新查询

java - jruby + 没有公共(public)构造函数

java - 使用 PDFBox 获取文本颜色

android - 序列化 CDT 项目设置遇到了

android - 何时使用 Firebase 通知注册主题?

firebase - 超过 firebase firestore 中的读取配额

java - Spring 3 的新特性是什么(与 Spring 2.5 相比)?

java - 从 sqlite 数据库中检索数据是通过此代码完成的

android - 在 Android 上将视频转码/转换为 Mp4

iOS Firebase 电子邮件验证