【问题标题】:DynamoDB update Item multi actionDynamoDB 更新项目多操作
【发布时间】:2016-09-08 03:17:49
【问题描述】:

我正在尝试更新 DynamoDB 表中的项目:

var params = {
        TableName: 'User',
    Key: {
        id: 'b6cc8100-74e4-11e6-8e52-bbcb90cbdd26',
    },
    UpdateExpression: 'ADD past_visits :inc, past_chats :inc',
    ExpressionAttributeValues: {
        ':inc': 1
    },
        ReturnValues: 'ALL_NEW'
    };
    docClient.update(params, function(err, data) {
        if (err) ppJson(err); // an error occurred
        else ppJson(data); // successful response
    });        

它正在工作。但我想像这样设置更多值(reset_time = :value'):

var params = {
        TableName: 'User',
    Key: {
        id: 'b6cc8100-74e4-11e6-8e52-bbcb90cbdd26',
    },
    UpdateExpression: 'ADD past_visits :inc, past_chats :inc, SET reset_time = :value',
    ExpressionAttributeValues: {
        ':inc': 1,
        ':value': 0
    },
        ReturnValues: 'ALL_NEW'
    };
    docClient.update(params, function(err, data) {
        if (err) ppJson(err); // an error occurred
        else ppJson(data); // successful response
    });

DynamoDb 能否在一个查询中支持多项操作?

【问题讨论】:

  • 如果有用,我可以要求接受答案吗?谢谢!

标签: amazon-dynamodb


【解决方案1】:

请按如下所述更改更新表达式。它应该可以工作。

第二个 ":inc" 和 SET 之间没有逗号。

UpdateExpression : "ADD past_visits :inc, past_chats :inc  SET reset_time = :value",

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-01-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-01
  • 2019-02-16
  • 1970-01-01
相关资源
最近更新 更多