title: How to automatically create indexes for Cloud Firestore?
body: <p>I have a Collection of <code>Lists</code> in which I store a bunch of documents. Each document contains a few details and a Collection of <code>users</code>. I store the users within the <code>users</code> Collection using the uid as a key and a boolean as a value. This means that only those users will be able to read that particular list. This is my database structure.</p>
  
  <p><a href="https://i.stack.imgur.com/LA4fm.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LA4fm.png" alt="enter image description here"></a>
  In my code I use this query:</p>
  
  <pre><code>FirebaseFirestore rootRef = FirebaseFirestore.getInstance();
  CollectionReference listsRef = rootRef.collection("Lists");
  Query query = listsRef.orderBy("date").whereEqualTo("users."+uid, true);
  </code></pre>
  
  <p>And I get the following error:</p>
  
  <pre><code>FAILED_PRECONDITION: The query requires an index. You can create it here: ...
  </code></pre>
  
  <p>If I go to the Console to create the required index, everything works fine. But is there a possibility to create the indexes automatically, because I cannot create manually an index for each user that joins my app. Is there a problem if I have a few sorting indexes for each user?</p>
  
  <p>Is there another workaround?</p>
  
  <p>Thanks in advance!</p>