简体   繁体   English

更新 dynamoDB 中的数组项

[英]Update array item in dynamoDB

In my dynamoDB , I have a table that structure as like as given below:在我的dynamoDB 中,我有一个结构如下所示的表:

 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 ?如何更新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) .使用以下 UpdateExpression 将值附加到列表: SET html = list_append(html, :html) The ExpressionAttributeValues would just be a mapping from :html to the string that you want to add. ExpressionAttributeValues 只是从:html到您要添加的字符串的映射。

Use the String Set attribute to update the list.使用字符串集属性更新列表。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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