2016-10-11 75 views
0

我正在尝试使用nodejs sdk在Dynamo Table上执行放置项目。我尝试使用相同的文件和其他一些变化,但似乎没有任何工作。每次我收到了同样的错误:无效的属性值类型:DynamoDB上的ValidationException Put

"message":"Invalid attribute value type" 
"code":"ValidationException" 
"time":"2016-10-11T06:32:26.361Z" 
"statusCode":400 
"retryable":false 

以下是相关的代码片段:

var params = { 
    TableName: "MY_Table_Name", 
    Item: { 
     "stringAtt": "stringValue", 
     "boolAtt": true, 
     "numAtt": 123, 
    }, 
}; 
docClient.put(params, function(err, data) { 
    if (err) ppJson(err); // an error occurred 
    else ppJson(data); // successful response 
}); 

我的表的索引如下:

Primary: Partition Key: stringAtt, Sort Key: boolAtt
GSI: Partition Key: boolAtt, Sort Key: numAtt

我不知道这是否是我的查询或错误的索引结构。

回答

0

BOOL数据类型不能是键属性(即分区或排序键)。分区或排序键数据类型可以是三种类型(下面列出)。如果您使用类型为'B'的Sort键创建表,则表示该排序键类型为二进制(即不是Bool)。

AttributeType: 'S | N | B'

S - the attribute is of type String

N - the attribute is of type Number

B - the attribute is of type Binary

当表与类型BOOL的密钥创建的API会抛出下面的异常。

Unable to create table. Error JSON: { 
    "message": "Member must satisfy enum value set: [B, N, S]", 
    "code": "ValidationException", 
+0

谢谢,有什么建议解决这个问题的方法?我的要求是获取具有指定布尔值true/false的所有项目。 – Tanmay

+0

您必须扫描表以获取boolAttribute = true/false的所有项目。 – notionquest

+0

您也可以使用数字类型,只限制使用值0和1。 这会导致大规模问题,但考虑到您的设计,我怀疑您会在该范围内。 – lod

相关问题