deg*_*egr 4 amazon-web-services amazon-dynamodb aws-sdk aws-sdk-nodejs
我需要执行这样的查询: select * from table where抽样日期如“2020-05-%”
为此,我呼吁
db.query({
TableName: "Tubes",
Select: "ALL_ATTRIBUTES",
IndexName: "sampling_date_idx",
KeyConditionExpression: " sampling_date > :sampling_date ",
ExpressionAttributeValues:{ ':sampling_date': {'S': '2020-05-'}}
}, function(error: AWSError, data: QueryOutput){
console.log(error, data);
})
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
{"errorType":"Error","errorMessage":"{\"message\":\"Query key condition not supported\",\"code\":\"ValidationException\",
Run Code Online (Sandbox Code Playgroud)
我的桌子:
this.tubes = new dynamodb.Table(this, "tubes", {
tableName: "Tubes",
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
partitionKey: {
name: "id",
type: dynamodb.AttributeType.STRING
},
pointInTimeRecovery: true,
removalPolicy: cdk.RemovalPolicy.RETAIN
});
this.tubes.addGlobalSecondaryIndex({
indexName: "sampling_date_idx",
sortKey: {
name: 'sampling_date_srt',
type: AttributeType.STRING
},
partitionKey: {
name: "sampling_date",
type: AttributeType.STRING,
},
})
Run Code Online (Sandbox Code Playgroud)
我认为您当前的代码中有两个问题 -
请阅读“KeyConditionExpression”部分 - https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html
简而言之,您只能对分区键执行相等性测试。
AWS 文档中给出的语法是 -
"ExpressionAttributeValues": {
"string" : {
"B": blob,
"BOOL": boolean,
"BS": [ blob ],
"L": [
"AttributeValue"
],
"M": {
"string" : "AttributeValue"
},
"N": "string",
"NS": [ "string" ],
"NULL": boolean,
"S": "string",
"SS": [ "string" ]
}
}
Run Code Online (Sandbox Code Playgroud)
在你的情况下,它可能是这样的 -
"ExpressionAttributeValues": {
":sampling_date": {"S": "2020-05-01"}
}
Run Code Online (Sandbox Code Playgroud)
我的经验是 C#,可能是这样的 -
ExpressionAttributeValues = new Dictionary<string, AttributeValue>()
{
{ ":sampling_date", new AttributeValue{S = "2005-05-01"} }
}
Run Code Online (Sandbox Code Playgroud)
为了解决您的问题,您可能需要使用另一个属性作为索引的分区键。Sample_date 只能用作排序键。
归档时间: |
|
查看次数: |
1136 次 |
最近记录: |