简体   繁体   中英

Update array item in dynamoDB

In my dynamoDB , I have a table that structure as like as given below:

 var params = {
      "TableName" : "pdfs",
      "Item" : {
          pdfid:  // Partition key
          html: [] // array attribute
       }
 };

I can insert new array data, just like as given code:

Insert array data

 var params = {
      "TableName" : "pdfs",
      "Item" : {
          pdfid: pdfid,
          html: [event.html]   // here "html" is an array, I just insert first array data
       }
 };

 dc.put(params, function(err, data) {
     ............................
 });

How can I update array in dynamoDB ?

  var params = {
      TableName: "pdfs",
      Key: {
         pdfid: event.pdfid
      },
      UpdateExpression: "SET html = :html",
      ExpressionAttributeValues: {
         ":html": ??????
      },
      ReturnValues: "ALL_NEW"
  };

Use the following UpdateExpression to append values to a list: SET html = list_append(html, :html) . The ExpressionAttributeValues would just be a mapping from :html to the string that you want to add.

Use the String Set attribute to update the list.

ExpressionAttributeValues: {
         ":html": {
              SS: aws.StringSlice(your_html_array)    
      }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM