Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The number of conditions on the keys is invalid dynamo db 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 use above code, i got res :

Unable to Edit 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 do I miss / any mistake??

like image 434
Rahul Tank Avatar asked Sep 13 '17 07:09

Rahul Tank


People also ask

Is it possible to query DynamoDB with just the hash key?

I have two DynamoDb tables, both with two key indexes, one is a HASH key and the other is a RANGE key. In the table where both keys are strings, I can query the database with just the HASH key like this (using the node sdk):

When are eq conditions applied to a query?

If a FilterExpression or QueryFilter is present, it will be applied after the items are retrieved. For a query on an index, you can have conditions only on the index key attributes. You must provide the index partition key name and value as an EQ condition.

What happens if I don't provide a sort key condition?

If you don't provide a sort key condition, all of the items that match the partition key will be retrieved. If a FilterExpression or QueryFilter is present, it will be applied after the items are retrieved.

How does DynamoDB compare binary data?

For Binary, DynamoDB treats each byte of the binary data as unsigned when it compares binary values. ComparisonOperator - A comparator for evaluating attributes, for example, equals, greater than, less than, and so on.


1 Answers

I think you have used multiple keys while creating table.

If you have used n number of keys while creating table, then here also you need to pass n number of keys.

Note below, we are passing in id1 and id2 keys as well.

Ex:

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 id1 and id2 with your keys

like image 135
Girish Rathod Avatar answered Oct 23 '22 11:10

Girish Rathod