title: Which is the correct way to scan a table on DynamoDB?
body: <p>As the title says, I want to know which is the best way to scan a table in Amazon DynamoDB, searching by <strong>another</strong> field than the primary key. </p>
  
  <p>I searched about this and read a lot, but I found this solution for me:</p>
  
  <pre><code>let DynamoDBServiceObj = new AWS.DynamoDB({apiVersion: '2012-08-10'});
  
  let params = {
     ExpressionAttributeValues: {
         ':hash' : { S: req.param('wildcard') }
     },
     ProjectionExpression: 'directory',
     FilterExpression: 'qrCode = :hash',
     TableName: 'business'
  };
  
  let business = await DynamoDBServiceObj.scan(params).promise();
  if (business.Count == 1) return res.ok();
  else return res.view('404');
  </code></pre>
  
  <p>This works for me, but I also read that perform an <strong>scan</strong> on a table is a bad idea, for performance and pricing. But, how to do it then?</p>
  
  <ul>
  <li><p>Which is the correct way to scan a table, searching by <strong>another</strong> than the primary key?</p></li>
  <li><p>What is the difference between <strong>DocumentClient</strong> and <strong>DynamoDB Object</strong>?</p></li>
  <li><p>I always use .get() for obtain what I want on DynamoDB. Is this a <strong>good</strong> or a <strong>bad</strong> <strong>practice</strong>?</p></li>
  </ul>
  
  <p>I read these posts, and I suppose that GSI is the solution, but I don't understand how it works.</p>
  
  <ul>
  <li><a href="https://aws.amazon.com/es/blogs/aws/now-available-global-secondary-indexes-for-amazon-dynamodb/" rel="nofollow noreferrer">Global Secondary Indexes (GSI)</a></li>
  <li><a href="https://stackoverflow.com/questions/20561446/dynamodb-scan-on-multiple-non-key-attribute">DynamoDB: Scan on multiple non key attribute</a></li>
  <li><a href="https://docs.aws.amazon.com/en_en/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.04.html" rel="nofollow noreferrer">Step 4: Query and Scan the table</a></li>
  <li><a href="https://docs.aws.amazon.com/en_en/sdk-for-javascript/v2/developer-guide/dynamodb-example-query-scan.html" rel="nofollow noreferrer">Querying and Scanning a DynamoDB Table</a></li>
  <li><a href="https://stackoverflow.com/questions/43452219/what-is-the-difference-between-scan-and-query-in-dynamodb-when-use-scan-query">What is the difference between scan and query in dynamodb?</a></li>
  <li><a href="https://stackoverflow.com/questions/44589967/how-to-fetch-scan-all-items-from-aws-dynamodb-using-node-js">How to fetch/scan all items from <code>AWS dynamodb</code> using node.js</a></li>
  </ul>