DynamoDB:使用 Node.js 将元素附加到列表

Leo*_*rdo 3 javascript amazon-web-services node.js amazon-dynamodb

这不起作用。有没有另一种方法可以做到这一点?cord是我要添加地图的列表。

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) { ... }
Run Code Online (Sandbox Code Playgroud)

Kha*_* T. 6

代替ADD,您可以使用SET该list_append函数(通常,AWS建议使用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);
}
Run Code Online (Sandbox Code Playgroud)