ntruiz
ntruiz

Reputation: 45

DynamoDB update using NODEjs: Syntax error; token: \"updated\", near: \"set updated =\""

Each item on my dynamoDB looks like the following

 {
  "status": "pending",
  "ccNumber":  "0012",
  "created":  "2018-03-07T16:42:02-04:00",
  "id": "14664d28-ef41-4228-99b5-6381a2a69f62",
  "amount":  "12",
  "invoice": "71200",
  "customerId": "00000"
}

I'm trying to update a field on this specific record and also adding more items. here's my params variable

 const params = {
  TableName: this.table,
  Key: { id },
  UpdateExpression: `set tranStatus = :status, updated = :updated, authTransacId = :authTransacId, avsResponse = :avsResponse, authCode = :authCode`,
  ExpressionAttributeValues: {
    ':status': data.status,
    ':updated': moment().utcOffset(-4).format(),
    ':authTransacId': data.transId,
    ':avsResponse': data.avsResponse,
    ':authCode': data.authCode
  },
  ReturnValues: "UPDATED_NEW"
}

I can't seem to find the issue with the new field: updated

Upvotes: 2

Views: 437

Answers (1)

Costin
Costin

Reputation: 3029

Can you console.log(params)?

I suspect that updated is a reserved word. It is a safe practice to use ExpressionAttributeNames in your params.

I supose you call .update(params), isn't it?

const params = {
  TableName: this.table,
  Key: { id },
  UpdateExpression: `set #a = :status, #b = :updated, #c = :authTransacId, #d = :avsResponse, #e = :authCode`,
  ExpressionAttributeValues: {
    ':status': data.status,
    ':updated': moment().utcOffset(-4).format(),
    ':authTransacId': data.transId,
    ':avsResponse': data.avsResponse,
    ':authCode': data.authCode
  },
  ExpressionAttributeNames: {
    '#a': 'tranStatus',
    '#b': 'updated',
    '#c': 'authTransacId',
    '#d': 'avsResponse',
    '#e': 'authCode',
  },
  ReturnValues: "UPDATED_NEW"
}

Upvotes: 2

Related Questions