title: In Firestore, how can you do a compound query involving a key in a map without creating an index for every key?
body: <p>In Firestore, how can you do a compound query involving a key in a map without creating an index for every key?</p>
  
  <p>For example, consider a collection which holds blog posts, and each blog post has categories. </p>
  
  <pre><code>Post {
      title: ..
      ...
      categories: {
          cats: true
          puppies: true
      }   
  }
  </code></pre>
  
  <p>In order to query posts in a particular category in a paginated way, we would do something like this:</p>
  
  <pre><code>let query = db.collection(`/posts`)
      .where(`categories.${categoryId}`, '==', true)
      .orderBy('createdAt')
      .startAfter(lastDate)
      .limit(5);
  </code></pre>
  
  <p>But it seems that this would require a composite index (<code>categories.&lt;categoryId&gt;</code> and <code>createdAt</code>) for every single category. Is there any way around this?</p>
  
  <p>In my case, it isn't feasible to create composite indices for every category since categories are user-generated, and could easily exceed 200 (the limit for composite indices in Firestore).</p>