updating a JSON array in AWS dynamoDB

后端 未结 3 1190
你的背包
你的背包 2020-12-11 20:19

My document looks like this:

{
  \"data\": {
      \"eventId\": \"20161029125458-df-d\",
      \"name\": \"first\",
      \"purpose\": \"test\",
      \"loca         


        
3条回答
  •  轮回少年
    2020-12-11 20:53

    you can store the index of list. while updating the list we can use them. For example ,

    {
    
    
    "data": {
          "eventId": "20161029125458-df-d",
          "name": "first",
          "purpose": "test",
          "location": "yokohama",
          "dateArray": [],
          "attendees": [
            {  
              "index":0,  
              "attendeeId": "2016102973634-df",
              "attendeeName": "lakshman",
              "personalizedDateSelection": {}
            },
            {
               "index":1,
              "attendeeId": "2016102973634-tyyu",
              "attendeeName": "diwaakar",
              "personalizedDateSelection": {}
            }
          ]
        }
    }
    const params = {
      TableName: "event",
      Key: {
        "eventId": eventId 
      },
      UpdateExpression: "SET attendees[attendee.index].attendeeName = :value",
      ExpressionAttributeValues: {
        ":value" : {"S":"karthik"}
      },
      ReturnValues: "ALL_NEW"
    };
    
    
    dynamo.update(params, (err, data) => {
      if (err) {
        return reject(err);
      }
      console.log(data.Attributes);
    });
    

提交回复
热议问题