Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ValidationException: ExpressionAttributeValues must not be empty

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"});
  }
});
like image 945
Leonardo Avatar asked Sep 06 '25 03:09

Leonardo


1 Answers

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!

like image 82
Alex F. Avatar answered Sep 07 '25 21:09

Alex F.