dynamodb-toolbox/dynamodb-toolbox

retrieve auto-generated partition key

Closed this issue · 1 comments

Just started using this library in one of my projects and have a quick(hopefully!) question - I have the partition key for my entity autogenerated using the default property, something like below -
id : { type: 'string', partitionKey: true, default: uuidv4() }

After a PUT, Is there a way for me to know the id generated?

Hey @vishnurpiper,
unfortunately there's no way to retrieve an item with a generated hash key you just PUT, it's a DynamoDB constraint (See here).

As a workaround, you have two options:

  1. Use update with returnValues: 'ALL_NEW'.
  2. Generate the UUID before the operation instead of using the default property on the id attribute.

Let me know if you have any other questions.