title: Firebase firestore query: "Error: 9 FAILED_PRECONDITION: The query requires an index. You can create it here"
body: <p>I have what I thought was a simple query on a collection called 'email':</p>
  
  <pre><code> const emailQuery = admin
      .firestore()
      .collection('email')
      .where('sendAt', '&gt;=', new Date())
      .where('orderId', '==', doc.orderId)
      .where('brandId', '==', doc.brandId);
  </code></pre>
  
  <p>I'm receiving the error in the subject of this post, indicating that I need to create an index for this query. I've tried creating a couple for the relevant fields, but I'm unsure of why it's needed since only one field is ordered--and the error remains despite these indexes:</p>
  
  <pre><code>sendAt -&gt; Ascending, brandId -&gt; Ascending, orderId -&gt; Ascending
  
  sendAt -&gt; Descending, brandId -&gt; Ascending, orderId -&gt; Ascending
  </code></pre>
  
  <p>I'm not specifying an <code>orderBy</code> as you can see. Also, <code>sendAt</code> is a date, while the other two are simple strings that don't need to be ordered. </p>
  
  <p>What kind index do I need, or how do I get past this error?</p>
  
  <p>Thanks!</p>