title: node.js AWS dynamodb updateItem for multiple values that may or may not be there
body: <p>I am using this aws-sdk in nodejs to access/update dynamodb entries.</p>
  
  <p>I have a document that is very long as shown in example below.</p>
  
  <pre><code>UID = 1
  sort_key = abc
  variable = X
  variable2 = y
  variable3 = z
  .....
  variable(n) = n2
  </code></pre>
  
  <p>I want to be able to structure and update from <a href="https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#update-property" rel="nofollow noreferrer">https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB/DocumentClient.html#update-property</a></p>
  
  <p>so that it can detect if there is no value for a specific variable that it won't update it.</p>
  
  <p>For example, on request may only have an update for variable 2 and 4 so I don't have any details on the others.</p>
  
  <p>Or am I correct in assuming I have to build javascript code that will create the UpdateExpression and ExpressionAttributeValues when I detect these specific values get entered?</p>
  
  <p>If thats the pattern then it's a bit tedious however I get it. thats just how it has to be done. I was just hoping there was an elegant solution.</p>
  
  <p>This is what I am thinking right now. In response to comment asking for the idea in code form.</p>
  
  <p>'''</p>
  
  <pre><code>            # Above this a load of if statments checking if the value is null. If not the name of the variable is added to the value listofvariables json
              example of json produced after checking all the keys one by one if they are null.
              var obj = { "variable 1": "test", "variable 2": "test2" };
              UpdateExpression = "set"
  
              for (const key of Object.keys(obj)) {
                      var addMevar =" " + key + " = :" + key + ","
                      var addMevalue = { key : obj[key] }
                      var UpdateExpression = UpdateExpression.concat(addme)
                      var ExpressionAttributeValues = ExpressionAttributeValues.concat(addMevalue)
              }
  
              var params = {
                TableName: 'Table',
                Key: { HashKey : 'hashkey' },
                UpdateExpression: UpdateExpression
                ExpressionAttributeValues: ExpressionAttributeValues
              };
  </code></pre>
  
  <p>'''</p>
  
  <p>What I really want is something like this.</p>
  
  <pre><code>var params = {
                    TableName: 'Table',
                    Key: { HashKey : 'hashkey' },
                    UpdateExpression: all the value here like usual 'set blablabla =something '
                    ExpressionAttributeValues: {value set to the values in the rest of my code. However some flag that says if null you don't update the value in DB as empty.}
                  };
  
  </code></pre>
  
  <p>Ultimately I know the building of the query works. I just hoping someone knew of a better way.</p>