title: How to design schema in order to optimize UI filters populations and filtering?
body: <p>Let's say in RDBS we have two tables:</p>
  
  <p><a href="https://i.stack.imgur.com/Hrcvu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hrcvu.png" alt="enter image description here"></a></p>
  
  <p>In the context of a user interface displaying <code>Users</code> details, if we want to have filters by <code>company name</code> and <code>size</code> we can perform fast SQL queries to get values in the format below:</p>
  
  <pre><code>CompanyID       CompanyName
  101             Microsoft
  102             Google
  ...
  
  CompanyIDsCSV   Size 
  101, 102        100000+
  ..
  </code></pre>
  
  <p>As data is normalized the operations are expected to be fast. </p>
  
  <p>In the context of MongoDB I can use the embedded collection:</p>
  
  <pre><code>{
     UserID: ...
    ,FirstName: ...
    ,LastName: ...
    ,Company:
     {
        ID: ...
       ,Name: ...
       ,Size: ...
     }
  }
  </code></pre>
  
  <p>But in order to load the data in the filters initially, I need to read all documents. Can one share how this can be optimize in the context of MongoDB?</p>
  
  <p>What I am thinking is:</p>
  
  <ul>
  <li>have the data embedded in order to read at once all details I need</li>
  <li>create separate collection with unique companies and used to populate filters values</li>
  <li>create index on <code>company.id</code> in order to search by it when filters are used</li>
  </ul>
  
  <p>In the MongoDB documentation there are guidelines for <a href="https://docs.mongodb.com/manual/core/data-model-design/#normalized-data-models" rel="nofollow noreferrer">Embedded and Normalized data models</a>, but I am wondering would be a bad practice to model my data like this?</p>
  
  <p>I know, I need to ensure the data between the embedded and normalized collections is the same, but I am ready to pay the cost in order to get maximum performance on read. </p>