简体   繁体   中英

How to get all documents in one reading Firebase

I am expanding a project originally made for mobiles, making a web management system with spring, for which the data is loaded by the mobiles to a Firestore db. My problem is that when I list all the documents in a collection, google counts the number of reads by the number of documents in that collection.

public List<MemberDTO> list() {
        List<MemberDTO> response = new ArrayList<>();
        MemberDTO post;
        ApiFuture<QuerySnapshot> querySnapshotApiFuture = getCollection().get();
        try {
            for (DocumentSnapshot doc : querySnapshotApiFuture.get().getDocuments()) {
                post = doc.toObject(MemberDTO.class);
                response.add(post);
            }
            return response;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
private CollectionReference getCollection() {
        return firebase.getFirestore().collection("MEMBERS");
    }

Therefore, having approximately 1000 documents in the production db, in one hour of use I reach the limit of 50,000 readings.

Getting all documents in a collection using a single firebase read, I got n number of reads where n is the number of documents.

That is the expected and documented behavior. This part of the pricing model is based on document reads, so you're charged per document that you read. If you want to be charged fewer document reads, the solution is to read fewer documents, for example by implementing pagination .

If you're new to Firestore, I recommend checking out the excellent video series Get to know Cloud Firestore . For this topic, there is an entire episode on Firestore pricing .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM