【发布时间】:2020-05-20 17:44:41
【问题描述】:
我正在尝试使用以下 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 });
});
}
【问题讨论】:
-
dynamo 不接受空字符串,为什么不放一些通用字符串或完全离开该字段?
-
你知道DDB是noSql吗?
-
您的问题与 NodeJS 无关。不能设置
"notes": null吗? -
来自文档
Attribute values cannot be null. String and Binary type attributes must have lengths greater than zero. -
截至 2020 年 6 月,DynamoDB 现在原生支持空字符串。确保关闭
convertEmptyValues,否则空字符串将被转换为NULL。 stackoverflow.com/a/62166912/1457398
标签: javascript node.js amazon-dynamodb