我想知道是否有一种方法可以选择应包含在 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/