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"});
}
});
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
This 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!