Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DynamoDB: Appending an element to a list using Node.js

This doesn't work. Is there another way to do this? cord is a list to which I want to add a 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) { ... }
like image 347
Leonardo Avatar asked Mar 13 '26 14:03

Leonardo


1 Answers

Instead of ADD, you could use SET with the list_append function (in general, AWS recommends using SET rather than ADD):

(NOTE: The list_append function name is case-sensitive)

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);
}
like image 137
Khalid T. Avatar answered Mar 16 '26 02:03

Khalid T.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!