简体   繁体   中英

get all document from 2 collection firestore

how to retrieve data from all documents in the first collection with a clause in the second collection.
I use this code but the data doesn't show up at all.. please help me..

dbf.collection("group").document().collection("member")
.whereEqualto("iduser", "098332")
                .orderBy("updatetime", Query.Direction.DESCENDING)
            .addSnapshotListener(new EventListener<QuerySnapshot>() {
                @Override
                public void onEvent(@Nullable QuerySnapshot value, @Nullable FirebaseFirestoreException error) {
                    List<DocumentSnapshot> list = value.getDocuments();

                    datalist.clear();
                    for (DocumentSnapshot d : list) {
                        final Modelfirestore c = d.toObject(Modelfirestore.class);
                        datalist.add(c);
                    

                    }
                    mAdapterss.notifyDataSetChanged();
                }
            });

I've tried with the script above but it doesn't work

Every time you call document() without an argument, it generates a references to a new, unique, non-existing document in your database. So you're querying a non-existing subcollection, which explains why you don't get any results.


If you want to query the member subcollection of a specific group document, specify the ID of that group document in the call to document(...) .


If you want to query across all member subcollections, you can use a collection group query .


If you want to query all member collections under groups , you can use a collection group query with the trick in Sam's answer here: CollectionGroupQuery but limit search to subcollections under a particular document

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