title: DynamoDB Product Table Filtering
body: <p>I'm taking my first dive into noSQL (AWS DynamoDB) and writing a nodejs app which will maintain a product catalog. The product catalog has 2 types of item - Product and Category. </p>
  
  <p>Products can appear in multiple categories. I'm really struggling to find a source of information on how best to approach this, I think using a query would be the right solution but ideally both the solution and the  data would be elegant.</p>
  
  <p>At present my products look a bit like:</p>
  
  <pre><code>{
    "productId": 12930,
    "productCode": "DIHA",
    "name": "6 Bottle Beer Pack",
    "onSale": true,
    "newItem": false,
    "relatedItems": [1240, 1201, 4508, 55067],
    "categoryIds": [1201, 1202, 1203, 1204]
  }
  </code></pre>
  
  <p>The aim is to be able to query products in a category e.g. 1203 and then filter by facets such as onSale &amp; newItem.</p>
  
  <p>I have seen an example whereby they flatten the categories like so</p>
  
  <pre><code>"category_1": 1201,
  "category_2": 1202,
  "category_3": 1203,
  "category_4": 1204,
  ...
  </code></pre>
  
  <p>But something about that approach doesn't sit right with me (inelegant?)</p>
  
  <p>I have played with using normalized tables e.g. CategoryProduct which lists the categoryIds with their related productIds.</p>
  
  <pre><code>{
    1201: [12930, 12931, 12932, 12933 ...],
    1202: [12930, 12678, 12679, 12680 ...],
    1203: [12930, 12500, 12501],
    1204: [12930, 12931],
    ...
  }
  </code></pre>
  
  <p>But if my understanding is right then this would be quite resource heavy and lead to multiple reads just to acquire the products to filter against</p>
  
  <p>Does anyone know of any tutorials or resources where filtering an entire catalog by categories or tags exists? I feel like I've trawled Google/GitHub/stackoverflow and not yet seen an example to go on.</p>
  
  <p>I'll be eternally grateful if someone could share their knowledge/resources with me.</p>