title: Why DynamoDB scan with Limit and FilterExpression not return the items that match the filter requirements?
body: <p>I need make a scan with limit and a condition on DynamoDB.  </p>
  
  <p>The <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html#ScanQueryLimit" rel="noreferrer">docs</a> says:</p>
  
  <blockquote>
    <p>In a response, DynamoDB returns all the matching results within the scope of the Limit value. For example, if you issue a Query or a Scan request with a Limit value of 6 and without a filter expression, DynamoDB returns the first six items in the table that match the specified key conditions in the request (or just the first six items in the case of a Scan with no filter). If you also supply a FilterExpression value, DynamoDB will return the items in the first six that also match the filter requirements (the number of results returned will be less than or equal to 6).</p>
  </blockquote>
  
  <p><br/><strong>The code (NODEJS):</strong></p>
  
  <pre><code>var params = {
      ExpressionAttributeNames: {"#user": "User"},
      ExpressionAttributeValues: {":user": parseInt(user.id)},
      FilterExpression: "#user = :user and attribute_not_exists(Removed)",
      Limit: 2,
      TableName: "XXXX"
  };
  
  DynamoDB.scan(params, function(err, data) {
      if (err) {
          dataToSend.message = "Unable to query. Error: " + err.message;
      } else if (data.Items.length == 0) {
          dataToSend.message = "No results were found.";
      } else {
          dataToSend.data = data.Items;
          console.log(dataToSend);
      }
  });
  </code></pre>
  
  <p><br/><br/><strong>Table XXXX definitions:</strong></p>
  
  <ul>
  <li>Primary partition key: User (Number)</li>
  <li>Primary sort key: Identifier (String)</li>
  <li>INDEX:
  
  <ul>
  <li>Index Name: RemovedIndex</li>
  <li>Type: GSI</li>
  <li>Partition key: Removed (Number)</li>
  <li>Sort key: -</li>
  <li>Attributes: ALL</li>
  </ul></li>
  </ul>
  
  <p><br />In code above, if I remove the <code>Limit</code> parameter, DynamoDB will return the items that match the filter requirements. So, the conditions are ok. But when I scan with <code>Limit</code> parameter, the result is empty.</p>
  
  <p>The XXXX table, has 5 items. Only the 2 firsts have the <code>Removed</code> attribute. When I scan without <code>Limit</code> parameter, DynamoDB returns the 3 items without <code>Removed</code> attribute.</p>
  
  <p>What i'm doing wrong?</p>