带有 DynamoDB 的 NodeJS 抛出错误“AttributeValue 可能不包含空字符串" [英] NodeJS with DynamoDB throws error "AttributeValue may not contain an empty string"

查看:19
本文介绍了带有 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 的 NodeJS 抛出错误“AttributeValue 可能不包含空字符串"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆