title: How to use whereEqualTo() and orderBy() in a Firebase Firestore query?
body: <p>I have the following collection in Firestore. All the documents are similar:</p>
  <p><a href="https://i.stack.imgur.com/PV2g5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PV2g5.jpg" alt="enter image description here" /></a></p>
  <p>I am trying to run the following query on it:</p>
  <pre class="lang-java prettyprint-override"><code>orders = new ArrayList&lt;&gt;();
  Log.d(&quot;cs50&quot;, &quot;email = &quot; + email);
  database.collection(&quot;Orders&quot;).whereEqualTo(&quot;Donor&quot;, email).whereEqualTo(&quot;isFulfilled&quot;, false).orderBy(&quot;timestamp&quot;, Query.Direction.DESCENDING).get()
          .addOnSuccessListener(new OnSuccessListener&lt;QuerySnapshot&gt;() {
              @Override
              public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                  Log.d(&quot;cs50&quot;, &quot;snapshots.size() = &quot; + queryDocumentSnapshots.size());
                  for (QueryDocumentSnapshot documentSnapshot : queryDocumentSnapshots) {
                      orders.add(documentSnapshot.getId());
                      Log.d(&quot;cs50&quot;, &quot;onSuccess() orders.size() = &quot; + orders.size());
                  }
              }
          }).addOnFailureListener(new OnFailureListener() {
      @Override
      public void onFailure(@NonNull Exception e) {
          Log.e(&quot;cs50&quot;, &quot;Error getting orders&quot;, e);
      }
  });
  
  notifyDataSetChanged();
  </code></pre>
  <p>I get the following output in my logcat:</p>
  <pre><code>2020-09-21 20:41:54.736 9560-9560/com.example.treeapp D/cs50: email = donor40@gmail.com
  2020-09-21 20:41:55.876 9560-9560/com.example.treeapp D/cs50: snapshots.size() = 0
  </code></pre>
  <p>The query isn't returning any document snapshot, as you can see from the logcat.</p>
  <p>My guess is that I may be using the wrong type of <code>Direction.DESCENDING</code> in <code>orderBy</code>. It's pretty likely I'm wrong. The IDE gives three options for  <code>Direction.DESCENDING</code>: <code>Query.Direction.DESCENDING</code>, <code>OrderBy.Direction.DESCENDING</code> and <code>StructuredQuery.Direction.DESCENDING</code>. As you can see, I'm using <code>Query.Direction.DESCENDING</code>. The other two types give an error in the IDE.</p>
  <p>I don't understand what exactly is going wrong. I don't get any error messages in my logcat, so there's no problem with security rules. And as you can see from the logcat output, the query actually runs, it just returns an empty <code>queryDocumentSnapshots</code>.</p>