2

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

1 Answer 1

2

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"
}
Sign up to request clarification or add additional context in comments.

1 Comment

Yes indeed! I did call update(params). Thanks! this worked. First time using dynamoDB. Will keep the ExpressionAttributeNames suggestion in mind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.