2

Is there any way to check is a subcollection exists and/or is empty (as in the collection exists but doesn't have documents inside it) ?

I want to display a "no appointment found" message if there's no appointment.

PS I am working with QuerySnapshots

This is what I have

colRef.whereEqualTo("type", "vaccination")
            .whereEqualTo("isDone", "false")
            .orderBy("timestamp").limit(1).get()
            .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                @Override
                public void onComplete(@NonNull Task<QuerySnapshot> task) {
                    if (task.isSuccessful()) {
                        for (QueryDocumentSnapshot document : Objects.requireNonNull(task.getResult())) {
                            appointment = document.toObject(Appointment.class); 
                            address.setText(appointment.getAddress());
                            dir.setText(appointment.getName());
                        }

                    }
                }
            })
            .addOnFailureListener(new OnFailureListener() {
                @Override
                public void onFailure(@NonNull Exception e) {
                    Log.e(TAG, ""+e);
                }
            });
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Metronom
  • 258
  • 2
  • 14

0 Answers0