Closed teebu closed 6 years ago
For example:
I have two date fields:
createdAt updatedAt
How would I go about doing that? I only want to create createdAt once, and update updatedAt every time I updated the record.
Hi,
conditional updates are somehow used internally by this library but undocumented,
insert() = PUT if partition (optionally sort) key do not exist, fail otherwise insert_or_update() = unconditional ADD insert_or_replace() = unconditional PUT
I'm preparing something like:
DynamoDB
.table(tableName)
.where('hash').eq('hashkey')
.where('range').eq('rangekey')
.if('number').gt(0)
.if('active').eq(true)
.update({
number: DynamoDB.inc(-1), // decrement until its 0 if 'active'
}, function( err, data ) {})
although this does not seem to fit you as doing the following will fail with "ConditionalCheckFailedException" when createdAt exists
.if('createdAt').undefined()
I`ll think of something and get back to you
-adrian
any update on this?
I'm trying to do the exact same things as @teebu updates on this would be nice after 2 years?
@M1chaelTran , @teebu
From the current docs for updateItem > updateExpression it seems AWS does not allow conditional update at attribute level
You can either:
.get()
and then .insert()
if item does not exit or .update()
otherwiseor
.insert()
, if error is ConditionalCheckFailedException
do an .update()
or
update()
, if error is ConditionalCheckFailedException
do an .insert()
Answer is: you can;t do this using one call, I'm closing this issue
How would I do it? Does this support that?