首页 > 解决方案 > 如何将空字符串作为 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 });

  });
}

标签: javascriptnode.jsamazon-dynamodb

解决方案


是的 Dynamodb 不能接受空字符串。所以编辑 aws 配置

var docClient = new AWS.DynamoDB.DocumentClient({ convertEmptyValues: true });

这行得通!


推荐阅读