不能在同一请求中同时使用表达式和非表达式参数
Can not use both expression and non-expression parameters in the same request
基本上,我有一个 table,其中有两个我正在尝试查询和过滤的索引。
查询部分适用于 Table 和索引,但是当我尝试过滤时出现问题:
ValidationException: Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {QueryFilter} Expression parameters: {KeyConditionExpression}
这是传递给 docClient.query() 的参数:
{
TableName: 'MyTable',
Limit: 15,
ScanIndexForward: false,
IndexName: 'user-date-index',
KeyConditionExpression: '#user = :yyyy',
ExpressionAttributeNames: { '#user': 'user' },
ExpressionAttributeValues: { ':yyyy': 'the_user_id' },
QueryFilter: { status: { AttributeValueList: [Array], ComparisonOperator: 'EQ' } }
}
当我使用相同的参数但没有 QueryFilter 调用查询时,我得到了正确的结果,但我仍然需要过滤(在这种情况下按状态,我还有大约 5 个其他选项可以过滤)。
我花了几个小时尝试不同的事情,但 AWS 文档不够清晰,也没有提供示例,我花了一整天才达到这一点。
QueryFilter
被认为是 Legacy Conditional Parameter。来自上一个link:
With the introduction of expression parameters (see Using Expressions in DynamoDB), several older parameters have been deprecated. New applications should not use these legacy parameters, but should use expression parameters instead.
改为 QueryFilter
recommends using FilterExpression
的文档。
使用 FilterExpression,您的查询可能与此类似:
{
TableName: 'MyTable',
Limit: 15,
ScanIndexForward: false,
IndexName: 'user-date-index',
KeyConditionExpression: '#user = :yyyy',
FilterExpression: '#status = :status',
ExpressionAttributeNames: { '#user': 'user', '#status': 'status' },
ExpressionAttributeValues: { ':yyyy': 'the_user_id', ':status': 'STATUS' }
}
基本上,我有一个 table,其中有两个我正在尝试查询和过滤的索引。 查询部分适用于 Table 和索引,但是当我尝试过滤时出现问题:
ValidationException: Can not use both expression and non-expression parameters in the same request: Non-expression parameters: {QueryFilter} Expression parameters: {KeyConditionExpression}
这是传递给 docClient.query() 的参数:
{
TableName: 'MyTable',
Limit: 15,
ScanIndexForward: false,
IndexName: 'user-date-index',
KeyConditionExpression: '#user = :yyyy',
ExpressionAttributeNames: { '#user': 'user' },
ExpressionAttributeValues: { ':yyyy': 'the_user_id' },
QueryFilter: { status: { AttributeValueList: [Array], ComparisonOperator: 'EQ' } }
}
当我使用相同的参数但没有 QueryFilter 调用查询时,我得到了正确的结果,但我仍然需要过滤(在这种情况下按状态,我还有大约 5 个其他选项可以过滤)。
我花了几个小时尝试不同的事情,但 AWS 文档不够清晰,也没有提供示例,我花了一整天才达到这一点。
QueryFilter
被认为是 Legacy Conditional Parameter。来自上一个link:
With the introduction of expression parameters (see Using Expressions in DynamoDB), several older parameters have been deprecated. New applications should not use these legacy parameters, but should use expression parameters instead.
改为 QueryFilter
recommends using FilterExpression
的文档。
使用 FilterExpression,您的查询可能与此类似:
{
TableName: 'MyTable',
Limit: 15,
ScanIndexForward: false,
IndexName: 'user-date-index',
KeyConditionExpression: '#user = :yyyy',
FilterExpression: '#status = :status',
ExpressionAttributeNames: { '#user': 'user', '#status': 'status' },
ExpressionAttributeValues: { ':yyyy': 'the_user_id', ':status': 'STATUS' }
}