title: Firestore: How to query a map object inside a collection of documents?
body: <p>My objective:</p>
  
  <p>The web app (similar to Google Drive) has 2 screens. </p>
  
  <p>First screen is 'My Story' which displays all the story documents whom I'm the owner.</p>
  
  <p>Second screen is 'Shared with me' which displays all the story documents that I'm either reader, writer, or commenter.</p>
  
  <p>We have this <strong>/stories/{storyid}</strong></p>
  
  <pre><code>{
    title: "A Great Story",
    content: "Once upon a time ...",
    roles: {
      alice: "owner",
      bob: "reader",
      david: "writer",
      jane: "commenter"
      // ...
    }
  }
  </code></pre>
  
  <p>Full data structure reference: <a href="https://firebase.google.com/docs/firestore/solutions/role-based-access" rel="noreferrer">https://firebase.google.com/docs/firestore/solutions/role-based-access</a></p>
  
  <p>Question: How to write the below query to fulfil the above objective?</p>
  
  <pre><code>db
  .collection('stories')
  .where(`roles.${uid}`, '==', 'owner')
  </code></pre>
  
  <p><strong>The above query does NOT work because it will require Firestore to index roles.alice, roles.bob, roles.david, roles.jane, and roles.[all_uid].</strong></p>
  
  <hr>
  
  <p>Edit #1: Found a related post (with no answers) asking about <a href="https://stackoverflow.com/q/51021192/3073280">Firestore querying with roles</a></p>