最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - DynamoDB: Appending an element to a list using Node.js - Stack Overflow

programmeradmin4浏览0评论

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

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) { ... }
Share Improve this question edited Nov 19, 2017 at 7:19 Khalid T. 10.6k5 gold badges49 silver badges57 bronze badges asked Nov 19, 2017 at 6:21 LeonardoLeonardo 951 gold badge4 silver badges10 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Instead of ADD, you could use SET with the list_append function (in general, AWS remends 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);
}

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) {
发布评论

评论列表(0)

  1. 暂无评论