0

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

Dharmaraj
  • 47,845
  • 8
  • 52
  • 84
  • If you don't have a direct question about Java avoid putting the Java tag. This will make your question more specific. – Taha Sami Mar 25 '22 at 05:37
  • 3
    @SC291 This question is about code in Java, and the `[java]` tag is appropriate. – chrylis -cautiouslyoptimistic- Mar 25 '22 at 05:55
  • "it doesn't work" doesn't provide enough information so we can help. What exactly didn't work? Please edit your question and add your database structure as a screenshot and indicate the exact data you want to get. – Alex Mamo Mar 25 '22 at 07:09

1 Answers1

1

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

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807