Number of key conditions is invalid: damo dyna with node js

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);
    }
});

when using the above code, I got res:

Unable to change patient error: {"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}

what will i miss / any error ??

+4
source share
1 answer

I think you used several keys when creating the table.

If you used the nnumber of keys when creating the table, then here you also need to pass the nnumber of keys:

Example:

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);
    }
});

Please replace id1and id2its keys

+1
source

Source: https://habr.com/ru/post/1685579/


All Articles