3

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) { ... }

2 Answers 2

7

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

Without seeing the error code it throws it looks like you should change add to set and don't forget the = sign.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.