javascript - 如何将空字符串作为 dynamodb 中字段的值传递?
问题描述
我正在尝试使用以下 json 数据进行发布请求。但我需要一个字段,即“注释”作为空字符串值传递。当我这样通过时,出现错误:
“一个或多个参数值无效:AttributeValue 可能不包含空字符串”。
我该如何解决这个问题?
//json data which i need to post
{
"storeId": "106",
"addressId": "1",
"managerId": "1",
"name": "Syammohan",
"contactNo": "9656985685",
"notes": "",
"bookingType": "Weddding Consult",
"bookingDate": "2019-05-02",
"bookingTime": "09:00 am"
}
function bookingDone(employee) {
var {
storeId,
addressId,
managerId,
name,
contactNo,
notes,
bookingType,
bookingStatus,
bookingTime
} = req.body
console.log("notes", notes);
const params = {
TableName: "Booking",
Item: {
id: id,
storeId: storeId,
addressId: addressId,
managerId: managerId,
name: name,
contactNo: contactNo,
notes: notes,
bookingType: bookingType,
bookingStatus: bookingStatus,
bookingDate: bookingDate,
bookingTime: bookingTime,
employeeId: employee.id
},
};
docClient.put(params, (error) => {
if (error) {
console.log(error);
res.status(400).json({ error: 'Could not create booking' });
}
// queue.push(JSON.stringify({ event: 'booking.booking.created', model: { 'Bookings': params.Item } }));
res.send(params.Item)
// res.json({ id, name, info });
});
}
解决方案
是的 Dynamodb 不能接受空字符串。所以编辑 aws 配置
var docClient = new AWS.DynamoDB.DocumentClient({ convertEmptyValues: true });
这行得通!
推荐阅读
- java - Android Kotlin:如何使用泛型创建继承类型的实例?
- rust - 迭代存储在弧中的dashmap
- python - 我今天在公共 wifi 区域安装 Python 包时收到此消息。我被锁定了一些帐户?这是什么?
- node.js - 如何通过 SSL 将 Apache 作为 Node.js 的前端代理
- html - 将 view.py 中的值传递给 html 中的 url 链接
- reactjs - 没有用户登录时,PrivateRoute 不会重定向到指定的路由
- javascript - React.js 中的拖放
- google-apps-script - 如何使用 Google Apps 脚本关闭 Slack 应用程序中的模式?
- javascript - React - HOC 与 utils 函数
- nreal - NReal adb 和 scrcpy 更新后不工作