title: DynamoDB data model secondary index search
body: <p>Folks,
    Given we have to store the following shopping cart data:</p>
  
  <pre><code> userID1         ['itemID1','itemID2','itemID3']
   userID2         ['itemID3','itemID2','itemID7']
   userID3         ['itemID3','itemID2','itemID1']
  </code></pre>
  
  <p>We need to run the following queries:</p>
  
  <ul>
  <li>Give me all items (which is a list) for a specific user (easy).</li>
  <li>Give me all users which have <code>itemID3</code> (<strong>precisely my question</strong>).</li>
  </ul>
  
  <p>How would you model this in DynamoDB?</p>
  
  <p>Option 1, only have the Hash key? ie</p>
  
  <pre><code>    HashKey(users)  cartItems
      userID1         ['itemID1','itemID2','itemID3']
      userID2         ['itemID3','itemID2','itemID7']
      userID3         ['itemID3','itemID2','itemID1']
  </code></pre>
  
  <p>Option 2, Hash and Range keys?</p>
  
  <pre><code>    HashKey(users)  RangeKey(cartItems)
      userID1         ['itemID1','itemID2','itemID3']
      userID2         ['itemID3','itemID2','itemID7']
      userID3         ['itemID3','itemID2','itemID1']
  </code></pre>
  
  <p>But it seems that range keys can only be strings, numbers, or binary...</p>
  
  <p>Should this be solved by having 2 tables?  How would you model them?</p>
  
  <p>Thanks!</p>