Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum value from Firebase Firestore collection

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

I have a firestore collection that has different documents under it. these documents have data within them(name,age,amount, etc.). is there a way i can return the highest or Maximum amount in the collection? I'm implementing this in java(android). In the case of the above structure, the Maximum will be 150. Thank you in advance

like image 846
Etornam Avatar asked Oct 23 '18 15:10

Etornam


People also ask

Does firebase have a limit?

While not a hard limit, if you sustain more than 1,000 writes per second, your write activity may be rate-limited. 256 MB from the REST API; 16 MB from the SDKs. The total data in each write operation should be less than 256 MB. Multi-path updates are subject to the same size limitation.

How much data we can store in firebase for free?

Storage for your Hosting content is at no cost up to 10 GB. If you are not on the Blaze plan, and you reach the 10 GB limit of no-cost Hosting storage, you won't be able to deploy new content to your sites.

Can firebase handle million users?

Queries with limited sorting and filtering functionality can be performed with the firebase database. Cloud firestore assures automatic scaling and can handle 1 million concurrent connections and 10,000 writes/second.


1 Answers

You have to use a query that is defined via a combination of orderBy() and limit(), as follows:

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

See the docs here https://firebase.google.com/docs/firestore/query-data/queries and here https://firebase.google.com/docs/firestore/query-data/order-limit-data

like image 111
Renaud Tarnec Avatar answered Sep 19 '22 16:09

Renaud Tarnec