How do you "upsert" a property to a DynamoDB row. E.g. SET address.state = "MA" for some item, when address does not yet exist?
I feel like I'm having a chicken-and-egg problem because DynamoDB doesn't let you define a sloppy schema in advance.
If address DID already exist on that item, of type M (for Map), the internet tells me I could issue an UpdateExpression like:
SET #address.#state = :value
with #address, #state, and :value appropriately mapped to address, state, and MA, respectively.
But if the address property does not already exist, this gives an error:
''' ValidationException: The document path provided in the update expression is invalid for update '''
So.. it appears I either need to:
- Figure out a way to "upsert"
address.state(e.g.,SET address = {}; SET address.state = 'MA'in a single command)
or
- Issue three (!!!) roundtrips in which I try it,
SET address = {};on failure, and then try it again.
If the latter.... how do I set a blank map?!?
Ugh.. I like Dynamo, but unless I'm missing something obvious this is a bit crazy..