'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?
Solution 1:[1]
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
}
Solution 2:[2]
Replacing:
var docClient = new AWS.DynamoDB.DocumentClient();
With:
var docClient = new AWS.DynamoDB();
Instantly solved this problem for me.
Solution 3:[3]
Just in case you came here and you are using Indexes, if your index is set to string and your data it's a Number, you need to delete that Index and create a new one with the correct data type. :)
Solution 4:[4]
Solution
The fact is that I was missing the data channel (myPeerConnection.createDataChannel("dataSendChannel");) and the correct createOffer parameters ({offerToReceiveAudio:!0,offerToReceiveVideo:!0}).
The following code generates a correct SDP offer which is accepted by Google.
const myPeerConnection = new RTCPeerConnection
myPeerConnection.createDataChannel("dataSendChannel");
myPeerConnection.createOffer({offerToReceiveAudio:!0,offerToReceiveVideo:!0}).then(function(offer) {
return myPeerConnection.setLocalDescription(offer);
})
.then(function() {
console.log(myPeerConnection.localDescription.sdp + "\n");
})
.catch(function(reason) {
console.log("An error occurred, so handle the failure to connect");
});
Also pay attention: if you don't send the newline character in the end of the offer string, you will get the following error:
{
"error": {
"code": 500,
"message": "Internal error encountered.",
"status": "INTERNAL"
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | stayingcool |
| Solution 2 | James Shapiro |
| Solution 3 | Javier Rojas |
| Solution 4 |
