gpt4 book ai didi

javascript - DynamoDB Local PutItem 中的 bool 字段

转载 作者:行者123 更新时间:2023-11-29 14:48:34 24 4
gpt4 key购买 nike

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

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);
});

根据文档, bool 值是允许的,当我在 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

关于javascript - DynamoDB Local PutItem 中的 bool 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29474294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com