title: Recover Data Firestore Collection
body: <p>I have a service scheduling screen.</p>
  
  <p>But there is a problem:</p>
  
  <p>I need to check if the date and time the user is trying to schedule is available or reserved. </p>
  
  <pre><code>Structure DB:
  Companies
  -Company ID (Document)
  --name
  --phone
  ---Schedules (Collection)
  ------Event1
  --------Hour: 08:30
  --------Date: 01/01/2018
  ------Event2
  --------Hour: 09:00
  --------Date: 05/01/2018
  ------Event3
  --------Hour: 10:30
  --------Date: 01/002/2018
  </code></pre>
  
  <p>I access Scheduling data with this code:</p>
  
  <pre><code>String dateExample = "01/01/2018"
  String hourExample = "08:30"
  
  FirebaseFirestore mDB = FirebaseFirestore.getInstance();
  CollectionReference mDBCompaniesSchedules = (CollectionReference) mDB.collection("Companies").document(mId_Company).collection("Schedules")
  .get()
      .addOnSuccessListener(new OnSuccessListener&lt;QuerySnapshot&gt;() {
      @Override
      public void onSuccess(QuerySnapshot documentSnapshots) {
  
  
          for (Schedules document : documentSnapshots.toObjects(Schedules.class)) {
  
              String dtSchedules = document.getSchedules_date();
              String hourSchedules = document.getSchedules_hour();
  
  
              if ( dtSchedules.equals(dateExample) &amp;&amp; hourSchedules.equals(hourExample) ){
  
                  //Execute a "Toast" and closes the operation
  
  
              } else {
  
                  //Call up the scheduling function.
                  startScheduling();              
              }   
  
          }
      }
  })
  </code></pre>
  
  <p>Process:</p>
  
  <p>I need to run this code and go through all the documents in that collection. I need to check and analyze whether the date and time of the schedule already exists.</p>
  
  <p><strong>If there is</strong>: Show a Toast and block.</p>
  
  <p><strong>If there is no</strong>: Executing a specific function for the schedule record ("startScheduling()").</p>
  
  <p>Problem:</p>
  
  <p>When the data exists (it will only be once) then it will work.</p>
  
  <p><strong>When there is no data, it falls into the ELSE loop. And it is executing several times the same function "startScheduling();".</strong></p>
  
  <p>I need some way to go through this collection and when I do not find any results, the function "startScheduling (), be executed only once.</p>