简体   繁体   中英

How to retrieve all documents from a collection in Firestore?

I want to show all the documents that are in a collection using ListView in my app. For this, I need to retrieve all the documents, right? How can I do this? I've searched a lot but couldn't find anything in Google Docs / any proper solution.

Be careful, as each document returned counts as a 'read'. Make sure you've read the pricing section of firestore. If you had 10,000 documents in this collection, every time you made this query you'd be using 10,000 reads.

Nevertheless, the query is:

FirebaseFirestore.getInstance()
            .collection("collectionname")
            .get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()) {
                        List<DocumentSnapshot> myListOfDocuments = task.getResult().getDocuments();
                    }
                }
            });

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