amazon-web-services - 是否可以选择要在 DynamoDB 中返回的字段?

标签 amazon-web-services amazon-dynamodb nosql

我想知道是否有一种方法可以选择应包含在 dynamodb 查询或扫描结果中的字段。我尝试使用 AttributesToGet

def filter_ga_account_by_email(self, email):
    response = Table.scan(
        FilterExpression=Attr('client_email').eq(email),
        AttributesToGet=['id'],
    )

    return response['Items']

现在我有这个错误:ClientError: An error occurred (ValidationException) when calling the Scan operation: Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {AttributesToGet} Expression parameters: {FilterExpression}

最佳答案

最简单的方法是添加projectionExpression 参数并指定要在字符串数组中返回的属性,一个工作示例:

    const getProducts = (user) => {
                    var params = {
                        TableName: process.env.PRODUCTS,
                        ScanIndexForward: false,
                        KeyConditionExpression: 'user = :hkey',
                        ExpressionAttributeValues: {
                            ':hkey': user,
                        },
                        Limit: 200,
                        ProjectionExpression: ['internal_type', 'requested_at']
                };
     return dynamoClient.query(params).promise();
}

关于amazon-web-services - 是否可以选择要在 DynamoDB 中返回的字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37876836/

相关文章:

xml - 上传时 Amazon S3 存储桶 MalformedXML 错误

node.js - AWS ElasticBeanstalk Amazon Linux 2 .platform 文件夹不复制 NGINX conf

mongodb - 如何处理 MongoDB/DynamoDB 中的循环文档?

python - 如何使用 PynamoDB 在代码中使用访问凭据而不是环境变量

node.js - 无法使用 UpdateItem 从列表中删除元素

mysql - 最适合高分榜的数据库类型

ruby-on-rails - Rails 环境中的 CQRS?

mongodb - hadoop中的Analytics(分析)实现

amazon-web-services - Amazon S3 存储桶返回 403 Forbidden

ruby - 使用 Ruby 删除 DynamoDB 表中的所有项目