Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

212
Views
Condition parameter type does not match schema type

I have a table in dynamoDB called 'Contributors'. I have a primary composite key where the hash key is 'UserId' and the sort key is 'NoteId'. I want to query for all the items belonging to a particular hashkey.

Now if I use aws-cli, following command works:

aws dynamodb query \
--table-name Contributors \
--key-condition-expression 'UserId = :UserId' \
--expression-attribute-values '{
    ":UserId": {"N":"2"}
}'

But when I write the query in Node.js, neither of the below 2 param objects work:

var params = {
    TableName: "Contributors",
    KeyConditionExpression: "#UserId = :UserId",
    ExpressionAttributeNames: {
        "#UserId": "UserId"
    },
    ExpressionAttributeValues: {
        ":UserId": { "N": "2" }
    }
};

OR this:

var params = {
    TableName: "Contributors",
    KeyConditionExpression: "#UserId = :UserId",
    ExpressionAttributeNames: {
        "#UserId": "UserId"
    },
    ExpressionAttributeValues: {
        ":UserId": "2"
    }
};

I get the following error:

ValidationException: One or more parameter values were invalid: Condition parameter type does not match schema type

What should be the correct param object?

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

The following code should work. Just give the value without double quotes. The DocumentClient will automatically interpret the data type.

var docClient = new AWS.DynamoDB.DocumentClient();

var params = {
    TableName: "Contributors",
    KeyConditionExpression: "#UserId = :UserId",
    ExpressionAttributeNames: {
        "#UserId": "UserId"
    },
    ExpressionAttributeValues: {
        ":UserId": 2
    }
};

docClient.query(params, function(err, data) {
    if (err) {
        console.error("Unable to read item. Error JSON:", JSON.stringify(err,
                null, 2));
    } else {
        console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
    }
});
over 4 years ago · Santiago Trujillo Report

0

I had the issue because of passing the data type along with the value. Just remove the data type DocumentClient will automatically interpret the data type and it works:

From:

ExpressionAttributeValues: {
 ":UserId": { "S": req.query.status }
}

To:

ExpressionAttributeValues: {
 ":UserId": req.query.status
}
over 4 years ago · Santiago Trujillo Report

0

Replacing:

var docClient = new AWS.DynamoDB.DocumentClient();

With:

var docClient = new AWS.DynamoDB();

Instantly solved this problem for me.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!