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/