Even though ExpressionAttributeValues is not empty it gives me this error ValidationException: ExpressionAttributeValues must not be empty
app.post('/gpsfromuser', passport.authenticate('jwt', {session: false}), (req, res) => {
var xcorpassed = req.body.xcor
var ycorpassed = req.body.ycor
console.log(xcorpassed);
console.log(ycorpassed);
var params = {
TableName:passengers,
Key:{
"pid": req.user.id
},
UpdateExpression: "set cordx=:x, cordy=:y",
ExpressionAttributeValues:{
":x":xcorpassed,
":y":ycorpassed
},
ReturnValues:"UPDATED_NEW"
};
console.log("Updating the item...");
docClient.update(params, function(err, data) {
if (err) {
console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2));
return res.status(200).json({msg: "success1"});
}
});
Even though ExpressionAttributeValues is not empty it gives me this error ValidationException: ExpressionAttributeValues must not be empty
app.post('/gpsfromuser', passport.authenticate('jwt', {session: false}), (req, res) => {
var xcorpassed = req.body.xcor
var ycorpassed = req.body.ycor
console.log(xcorpassed);
console.log(ycorpassed);
var params = {
TableName:passengers,
Key:{
"pid": req.user.id
},
UpdateExpression: "set cordx=:x, cordy=:y",
ExpressionAttributeValues:{
":x":xcorpassed,
":y":ycorpassed
},
ReturnValues:"UPDATED_NEW"
};
console.log("Updating the item...");
docClient.update(params, function(err, data) {
if (err) {
console.error("Unable to update item. Error JSON:", JSON.stringify(err, null, 2));
} else {
console.log("UpdateItem succeeded:", JSON.stringify(data, null, 2));
return res.status(200).json({msg: "success1"});
}
});
Share
Improve this question
asked Oct 3, 2017 at 8:47
LeonardoLeonardo
951 gold badge4 silver badges10 bronze badges
5
- Following information will help to identify what's the issue: 1. what is the value of xcorpassed and ycorpassed when update is executed? 2. what is doc client? how did you create it? 3. output of execution of this function and the exact error that you faced. – Neeraj Sharma Commented Oct 3, 2017 at 16:29
- Docclient is instantiated from aws sdk, xcorpassed and ycorpassed are strings. The output is an error that I posted in the description. – Leonardo Commented Oct 3, 2017 at 17:22
- Leonardo, I think I got what you shared already. My request was to see the code execution, what values are being passed at run time etc. I tried this code and it all works fine in my local. It would help if you can show me the run time execution if this function, like I'm sharing in next ment. Most likely, some values are not as expected during run time and your code works is a proof of that. – Neeraj Sharma Commented Oct 3, 2017 at 22:42
-
test-so:515> node test-so.js testx testy Updating the item... {"TableName":"test-so-table","Key":{"pid":"test"},"UpdateExpression":"set cordx=:x, cordy=:y","ExpressionAttributeValues":{":x":"testx",":y":"testy"},"ReturnValues":"UPDATED_NEW"} UpdateItem succeeded: { "Attributes": { "cordy": "testy", "cordx": "testx" } }
– Neeraj Sharma Commented Oct 3, 2017 at 22:42 - Ok I handled it thanks for your interest. The problem was in another function, the function that set up passport-jwt. Cheers – Leonardo Commented Oct 4, 2017 at 7:07
1 Answer
Reset to default 3This error occurs if the values of the Expression Attributes are undefined.
For debugging, I had the values of the Expression Attributes printed before the params were initialized.
console.log('X Coordinate: ' + xcorpassed);
console.log('Y Coordinate: ' + ycorpassed);
I hope the answer helps!