SamVerschueren / dynongo

MongoDB like syntax for DynamoDB
MIT License
58 stars 16 forks source link

Using same field on update expression and where condition causes update value to be overwritten #81

Closed onhate closed 4 years ago

onhate commented 4 years ago

In an operation where you have the same field on update clause and where clause, the value on the where clause overwrites the values from the update.

await Table.update({id: '5'}, {$set: {foo: null}}).where({foo: 'bar'}).exec();

I would expect the query to be something like this:

{
        TableName: 'Table',
        ReturnValues: 'ALL_NEW',
        Key: {
            id: '5'
        },
        UpdateExpression: 'SET #k_foo=:v_foo',
        ExpressionAttributeNames: {
            '#k_foo': 'foo',
            '#k_id': 'id'
        },
        ExpressionAttributeValues: {
            ':v_foo': null,
            ':v_foo_1': 'bar',
            ':v_id': '5'
        },
        ConditionExpression: '(#k_id=:v_id) AND (#k_foo=:v_foo_1)'
    }

but it comes as this, and instead of setting the foo value to null it sets it back to bar.

{
        TableName: 'Table',
        ReturnValues: 'ALL_NEW',
        Key: {
            id: '5'
        },
        UpdateExpression: 'SET #k_foo=:v_foo',
        ExpressionAttributeNames: {
            '#k_foo': 'foo',
            '#k_id': 'id'
        },
        ExpressionAttributeValues: {
            ':v_foo': 'bar',
            ':v_id': '5'
        },
        ConditionExpression: '(#k_id=:v_id) AND (#k_foo=:v_foo)'
    }