Home > Software design >  get data with query from document collection and document subcollection in firestore
get data with query from document collection and document subcollection in firestore

Time:03-28

I have a collection with "grup" name and have a subcollection named "anggota".

Please help me, how to display data by query referring to collection document and subcollection document.

Firestore collection:

collections in my firestore

I've tried with this query but it doesn't work, the data doesn't appear

db.collection("grup").document().collection("anggota")
            .whereEqualTo("iduser", idUser)
            .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();
            }
        });

CodePudding user response:

When you are using the following query:

                                         
  • Related