2

I want to increment a number value 'count' in dynamoDB. The problem I've is that I'm not sure if the key (pk,sk) actually exists.

for a given <pk,sk>
 - if <pk,sk,count> exists increment it by 1
 - if it is not exists add <pk,sk, count = 0>

I can do it in two separate queries but can it done in the same request?

Thanks, Omer

omer727
  • 7,117
  • 6
  • 26
  • 39
  • 1
    This is answered here https://stackoverflow.com/a/66308829/7793122 – derpirscher Feb 26 '22 at 20:37
  • @derpirscher Thanks, This really helped me. I tried to search for it in google\stackoverflow and couldn't find it. – omer727 Feb 26 '22 at 23:35
  • By the way, @omer727, one potential correction to your question: usually if the item doesn't exist you want to set its count to 1, not to 0 as you said in your question (in other words, it's like you initialized it to 0 and then incremented it normally). – Nadav Har'El Feb 27 '22 at 07:16
  • I'm a developer I'm starting to count at 0 not at 1. :) But yes, you are right of course. – omer727 Feb 27 '22 at 07:23
  • The "Counting Numbers" set starts at 1. – Cory Silva Mar 02 '22 at 07:58

0 Answers0