过滤后如何限制DynamoDB? [英] How can I do DynamoDB limit after filtering?

查看:108
本文介绍了过滤后如何限制DynamoDB?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用以下逻辑实现DynamoDB扫描:

I would like to implement a DynamoDB Scan with the following logic:

扫描->过滤(布尔值是或否)->限制(用于分页) )

但是,我只能使用以下逻辑实现扫描:

However, I have only been able to implement a Scan with this logic:

扫描->限制(用于分页)->过滤(布尔值对或错)

如何实现?

下面是我编写的实现第二个扫描逻辑的示例:

Below is an example I have written that implements the second Scan logic:

    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) => {
        if (errorResult) {
            errorResult._status = 500;
            return reject(errorResult);
        }

        return resolve(result);
    });

此代码类似于第二个代码。

This codes works like second one.

扫描->限制->过滤

推荐答案

DynamoDB LIMIT的工作原理如下(即第二个)方法)。

The DynamoDB LIMIT works as mentioned below (i.e. second approach in your post) by design. As it works by design, there is no solution for this.

LastEvaluatedKey应该用于获取后续扫描的数据。

LastEvaluatedKey should be used to get the data on subsequent scans.

扫描->限制(用于分页)->过滤(布尔值是或否)


在请求中,将Limit参数设置为
您希望DynamoDB在返回结果之前要处理的项目数。

In a request, set the Limit parameter to the number of items that you want DynamoDB to process before returning results.

在响应中,DynamoDB返回所有限制值在
范围内的匹配结果。例如,如果您发出查询或扫描
请求,其Limit值为6,并且没有过滤表达式,则
DynamoDB返回表中与
指定键匹配的前六个项目。请求中的条件(如果是不带过滤器的扫描,则为前六个项目
)。如果您还提供了
FilterExpression值,则DynamoDB将返回前
项中的第6个也符合过滤器要求的项目(返回的结果
的数目将小于或等于6)。

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).

对于查询或扫描操作,如果该操作未返回表中所有匹配的
项,则DynamoDB可能会返回
LastEvaluatedKey值。 。要获取匹配项的完整计数,请从上一个请求中获取
的LastEvaluatedKey值,并将其用作下一个请求中的
ExclusiveStartKey值。重复此操作,直到
DynamoDB不再返回LastEvaluatedKey值。

For either a Query or Scan operation, DynamoDB might return a LastEvaluatedKey value if the operation did not return all matching items in the table. To get the full count of items that match, take the LastEvaluatedKey value from the previous request and use it as the ExclusiveStartKey value in the next request. Repeat this until DynamoDB no longer returns a LastEvaluatedKey value.

这篇关于过滤后如何限制DynamoDB?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆