DynamoDB Local PutItem 中的布尔字段

Boolean fields in DynamoDB Local PutItem

我在本地 DynamoDb 中有一个简单的 table 并尝试放置这样的项目:

var options = {name : "test",
            creator : "Testcreator", description : "test",
            moderators : ["Testmoderator"]};

var obj = {
  name: {"S": options.name},
  restricted: {"BOOL": options.restricted || false},
  creator: {"S": options.creator},
  description: {"S": options.description || ""},
  moderators: {"SS" : options.moderators || []}
};
var params = {
  "TableName": "MY_TABLE",
  "Item": obj,
  Expected: {
    name: {Exists: false}
  }
};
dynamodb.putItem(params, function (err, data) {
    ppJson(err);
});

根据文档,布尔值是允许的,当我在 DynamoDB Local shell 中尝试此代码时出现以下错误:

"code":"UnexpectedParameter",
"message":"Unexpected key 'BOOL' found in params.Item['restricted']"
...

我的代码是否有错误,或者这是 javascript API 的问题?

我启用了 DynamoDB 本地日志记录以查看引擎生成的内部错误,这是我在尝试放置像您这样的项目后得到的结果:

[LocalDynamoDBServerHandler] - body:
{"TableName":"MY_TABLE","Item":{"name":{"S":"test"},"restricted":{"BOOL":true},"
creator":{"S":"Testcreator"}}}
_LOG_2015-04-07 08:25:26,549 ERROR [com.amazonaws.services.dynamodbv2.local.serv
er.LocalDynamoDBServerHandler] - Unknown error
com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized f
ield "BOOL" (class com.amazonaws.services.dynamodbv2.model.AttributeValue), not
marked as ignorable (6 known properties: , "SS", "BS", "B", "S", "NS", "N"])
 at [Source: [B@806204; line: 1, column: 78] (through reference chain: com.amazo
naws.services.dynamodbv2.model.PutItemRequest["Item"]->com.amazonaws.services.dy
namodbv2.model.AttributeValue["BOOL"])

根据日志,目前看来 DynamoDB Local 唯一支持的类型如下:

["SS", "BS", "B", "S", "NS", "N"]

您可以尝试一些替代方案,例如:

https://www.npmjs.com/package/dynalite