title: Is it possible to upsert nested fields in DynamoDB?
body: <p>I would like to 'upsert' a document in DynamoDB.  That is, I would like to specify a key, and a set of field/value pairs.  If no document exists with that key, I want one created with that key and the key/value pairs I specified.  If a document exists with that key, I want the fields I specified to be set to the values specified (if those fields did not exist before, then they should be added).  Any other, unspecified fields on the existing document should be left alone.</p>
  
  <p>It seems I can do this pretty well with the <a href="http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/API_UpdateItem_v20111205.html" rel="noreferrer"><code>UpdateItem</code></a> call, when the field/value pairs I am setting are all top-level fields.  If I have nested structures, <code>UpdateItem</code> will work to set the nested fields, as long as the structure exists.  In other words, if my existing document has <code>"foo": {}</code>, then I can set <code>"foo.bar": 42</code> successfully.</p>
  
  <p>However, I don't seem to be able to set <code>"foo.bar": 42</code> if there is no <code>foo</code> object already (like in the case where there is no document with the specified field at all, and my 'upsert' is behaving as an 'insert'.</p>
  
  <p>I found <a href="https://forums.aws.amazon.com/thread.jspa?threadID=162907" rel="noreferrer">a discussion</a> on the AWS forums from a few years ago which seems to imply that what I want to do cannot be done, but I'm hoping this has changed recently, or maybe someone knows of a way to do it?</p>