javascript - 动态数据库 : Appending an element to a list using Node. js

标签 javascript node.js amazon-web-services amazon-dynamodb

这行不通。还有另一种方法吗? cord 是我要添加 map 的列表。

var params5 = {
  TableName: 'rides',
  Key: {
    'rid': data2.Items[0].rid
  },
  UpdateExpression: 'add cord :x',
  ExpressionAttributeValues: {
    ':x': [{date: secondStartDate.toString(), latitude: xcorpassed, longitude: ycorpassed}]    
  },
  ReturnValues: 'UPDATED_NEW'
}
docClient.update(params5, function (err5, data5) { ... }

最佳答案

您可以将 SETlist_append 函数一起使用,而不是 ADD(通常,AWS recommends 使用 SET 而不是 ADD):

(注意:list_append函数名区分大小写)

var params = {
  TableName: "rides",
  Key: {
    "rid": data2.Items[0].rid
  },
  UpdateExpression: "SET #c = list_append(#c, :vals)",
  ExpressionAttributeNames: {
     "#c": "cord"
  },
  ExpressionAttributeValues: {
    ":vals": [{date: secondStartDate.toString(), latitude: xcorpassed, longitude: ycorpassed}]    
  },
  ReturnValues: "UPDATED_NEW"
}

docClient.update(params, function (err, data) {
   if (err) console.log(err);
   else console.log(data);
}

关于javascript - 动态数据库 : Appending an element to a list using Node. js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47374236/

相关文章:

javascript - 使用 JS 和 HTML 的 Google map API(从地点 A 到地点 b 的方向)

javascript - Javascript 的正则表达式只允许字母数字

javascript - Puppeteer:在waitForNavigation 后page.evaluate 不起作用,调试在page.evaluate 内部不起作用

ftp - 如何配置 Coda 以适用于我的 Amazon EC2 实例?

javascript - 加载图表后 Highstock 更改 xAxis minRange

javascript - Node JS - 从同一文件中的另一个方法调用一个方法

node.js - 使用 tfjs-node 时添加类型

amazon-web-services - 如何将 AWS CLI 的输出保存在变量中?

amazon-web-services - 如何在启动时为root用户设置环境变量?

javascript - 为什么资源在 Fullcalendar 中不显示