How can I do DynamoDB limit after filtering?
<p>I would like to implement a DynamoDB Scan with the following logic:</p>

<p><strong>Scanning -> Filtering(boolean true or false) -> Limiting(for pagination)</strong></p>

<p>However, I have only been able to implement a Scan with this logic:</p>

<p><strong>Scanning -> Limiting(for pagination) -> Filtering(boolean true or false)</strong></p>

<p>How can I achieve this?</p>

<p>Below is an example I have written that implements the second Scan logic:</p>

<pre><code>    var parameters = {
        TableName: this.tableName,
        Limit: queryStatement.limit
    };
    if ('role' in queryStatement) {
        parameters.FilterExpression = '#role = :role';
        parameters.ExpressionAttributeNames = {
            '#role': 'role'
        };
        parameters.ExpressionAttributeValues = {
            ':role': queryStatement.role
        };
    }
    if ('startKey' in queryStatement) {
        parameters.ExclusiveStartKey = { id: queryStatement.startKey};
    }

    this.documentClient.scan(parameters, (errorResult, result) =&gt; {
        if (errorResult) {
            errorResult._status = 500;
            return reject(errorResult);
        }

        return resolve(result);
    });
</code></pre>

<p>This codes works like second one.</p>

<p><strong>Scanning -> Limiting -> Filtering</strong></p>