How to remove a nested attribute from dynamodb table?

126 Views Asked by At

How to remove a nest attribute from dynamodb table on the basis of id? I m using nodejs(Typescript) with local dynamodb.


    // check if post exists
    const post = await dynamo.get({
      TableName: "PostTable",
      Key: { id: event.body.postId }
    }).promise();
    if (!post.Item) {
      return formatJSONResponse({
        message: `no post with this id`,
        statuscode: 404

      });
    }
    const params = {
      TableName: "PostTable",
      Key: { id: event.body.postId },
      UpdateExpression:
        "REMOVE comments.#id",
      ExpressionAttributeValues: {
         "#id": event.body.id 
      },
      ReturnValues : "UPDATED_NEW"
    }

   
  let res=  await dynamo.update(params).promise();
    return formatJSONResponse({
      message: `Comment has been removed
      event,
      result: res
    });

dynamobdb table picture

0

There are 0 best solutions below