简体   繁体   中英

CollectionGroup query in firestore android studio

I am not able enter into for loop. it is not showing any error. when I try to debug it is not entering for loop. after entering into for loop only it can retrieve result. can any one help?

Query query =fstore.collectionGroup("ride").whereEqualTo("from",from1).whereEqualTo("to",to1).whereEqualTo("date",date);
query.get().addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {

@Override
public void onSuccess(QuerySnapshot snapshots) {
      for (QueryDocumentSnapshot queryDocumentSnapshot:snapshots)
           {                 
              String source = queryDocumentSnapshot.getString("from");
              String destination = ueryDocumentSnapshot.getString("to");
              String date1 = queryDocumentSnapshot.getString("date");
              String time = queryDocumentSnapshot.getString("time");
              String vehicle = queryDocumentSnapshot.getString("vehicle number");
              String cost  = queryDocumentSnapshot.getString("Cost per person");
              String seats = queryDocumentSnapshot.getString("number of seats");
              String model = queryDocumentSnapshot.getString("car model");
              data += source+" "+destination+" "+date1+" "+time+" "+vehicle+" "+cost+" "+seats+" "+model+"\n";
           }
});

enter image description here

In the reference you may find following sentence:

Before using a collection group query, you must create an index that supports your collection group query. You can create an index through an error message, the console, or the Firebase CLI.

From the same reference example it seems that code is done properly. Of course we do not know what do you have in from1 , to1 and date variables. From the screenshot it seems that date has strange format in your database. As well I am not sure how it will work with multiple whereEqualTo methods.

So many think could go wrong here, but if I were in your shoes I would start with checking the indexes, and than start from building query with single whereEqualTo trying to get anything from database, exactly like in the reference example.

If you succeed than you can extend it to more sophisticated solutions.

I hope it will help!

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