使用 AWS re:Post 即表示您同意 AWS re:Post 使用條款

DynamoDB - Is it possible to query with a filter without data types?

0

Is it possible to omit the data types specification when running a Amazon DynamoDB Query with a QueryFilter or FilterExpression.

For example:

"AttributeValueList": [ {"S": "No One You Know"} ]

(from here)

I couldn't find a way to do it. Am I missing something?

已提問 4 年前檢視次數 1097 次
1 個回答
0
已接受的答案

The low-level Query API requires specifying the data type:

https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html

However, there are higher-level Document Clients available that abstract this for you, allowing you to pass a value (string, number, bool, etc.) as-is to the higher-level query API, and the DocumentClient will translate that to the low-level API for you. Big time saver:

https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/dynamodb-example-document-client.html https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html

Example:

var params = {
  TableName: 'Table',
  IndexName: 'Index',
  KeyConditionExpression: 'HashKey = :hkey and RangeKey > :rkey',
  ExpressionAttributeValues: {
    ':hkey': 'key',
    ':rkey': 2015
  }
};

var documentClient = new AWS.DynamoDB.DocumentClient();

documentClient.query(params, function(err, data) {
   if (err) console.log(err);
   else console.log(data);
});

https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#query-property

Also, per docs:

QueryFilter - This is a legacy parameter. Use FilterExpression instead. For more information, see QueryFilter in the Amazon DynamoDB Developer Guide.

已回答 4 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南