带有 DynamoDB 的 NodeJS 抛出错误“AttributeValue 可能不包含空字符串"
我对 DynamoDB 不能接受空字符串作为属性值这一事实有疑问.如果有空字符串值,我总是必须在前端检查,否则 API 调用将由于 Dynamo DB 抛出的错误一个 AttributeValue 可能不包含空字符串"而失败.
I had a problem with the fact that DynamoDB cannot accept empty strings as value in attributes. I always had to check in the front end if there is an empty string value otherwise the API call would fail due to the error "An AttributeValue may not contain an empty string" that Dynamo DB would throw.
如果有一个递归函数可以删除根据 DynamoDB 无效的属性,以便 DynamoDB 中的 putItem 或更新请求起作用,我正在徘徊.
I was wandering if there is a recursive function that would remove the attributes that are not valid according to DynamoDB in order for the putItem or update request in DynamoDB to work.
推荐答案
关于 2017 年 1 月 3 日合并 #1283 更新了 AWS.DynamoDB.DocumentClient constructor-property 通过将标志 convertEmptyValues
放入客户端对象的选项字段来允许空值.
Latest update on Jan 3 2017 Merge #1283 updated the AWS.DynamoDB.DocumentClient constructor-property to allow for empty values by putting the flag convertEmptyValues
into the options field of the client object.
例子:
const DynamoDB = new AWS.DynamoDB.DocumentClient( {
convertEmptyValues: true
} );
值得注意的问题
- DynamoDB.DocumentClient 应该支持空字符串属性#833李>
- 尊重 DynamoDB 文档客户端 #1281 中地图和列表的 convertEmptyValues 选项一个>
- 修复/doc客户端空嵌套成员#1283
- AWS 论坛线程 ID #90137
- 空属性会导致 DynamoDb boto/boto3 #1035 的 ValidationException
相关文章