DynamoDB - 可以在没有数据类型的情况下使用过滤器进行查询吗?

0

【以下的问题经过翻译处理】 在运行带有QueryFilter或FilterExpression的Amazon DynamoDB查询时,是否有可能省略数据类型规范?

例如:

"AttributeValueList": [{ "S":“您不认识的任何人” }]

(来源在这里

我没有找到这样做的方法。我错过了什么吗?

profile picture
EXPERT
asked 8 months ago20 views
1 Answer
0

【以下的回答经过翻译处理】 低级别的查询 API 需要指定数据类型:

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

但是,也有更高级别的文档客户端可用,可为您抽象这个过程,允许您将一个值(字符串、数字、布尔等)原样传递到更高级别的查询 API 中,并且文档客户端会为您将其转换为低级别的 API,从而节省大量时间:

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

例子:

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

另外,根据文档:

QueryFilter - 这是一个遗留参数。请改用 FilterExpression。有关更多信息,请参阅 Amazon DynamoDB 开发人员指南中的 QueryFilter。

profile picture
EXPERT
answered 8 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions