密钥上的条件数是带有节点js的无效dynamo db

问题描述 投票:6回答:1
docClient.update({
    TableName: 'patient',
    Key: {
        "patientId": "TIGERPAT0001"
    },
    UpdateExpression: "set title = :x, name = :y",
    ExpressionAttributeNames: {
        "#name": "name"
    },
    ExpressionAttributeValues: {
        ":x": 'title value abc',
        ":y": 'name value xyz'
    }
}, function (err, data) {
    if (err) {
        json.status = '0';
        json.result = { 'error': 'Unable to Edit Patient : ' + JSON.stringify(err) };
        res.send(json);
    } else {
        json.status = '1';
        json.result = { 'sucess': 'Patient Edited Successfully :' };
        res.send(json);
    }
});

当使用上面的代码时,我得到了res:

无法编辑患者错误:{"message":"The number of conditions on the keys is invalid","code":"ValidationException","time":"2017-09-13T07:12:56.608Z","requestId":"a01c707c-86b4-41a5-a1c5-92b9ea07c026","statusCode":400,"retryable":false,"retryDelay":6.368631970657979}

我错过了什么/任何错误?

node.js amazon-dynamodb
1个回答
3
投票

我认为你在创建表时使用了多个键。

如果您在创建表时使用了n键数,那么您还需要传递n键数:

例如:

docClient.update({
    TableName: 'patient',
    Key: {
        "patientId": "TIGERPAT0001",
        "id1": "id1value",
        "id2": "id2value"
    },
    UpdateExpression: "set title = :x, name = :y",
    ExpressionAttributeNames: {
        "#name": "name"
    },
    ExpressionAttributeValues: {
        ":x": 'title value abc',
        ":y": 'name value xyz'
    }
}, function (err, data) {
    if (err) {
        json.status = '0';
        json.result = { 'error': 'Unable to Edit Patient : ' + JSON.stringify(err) };
        res.send(json);
    } else {
        json.status = '1';
        json.result = { 'sucess': 'Patient Edited Successfully :' };
        res.send(json);
    }
});

请用钥匙替换id1id2

© www.soinside.com 2019 - 2024. All rights reserved.