Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a 'NOT IN' comparator in DynamoDB using query or scan

I read this document http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Condition.html

maybe no condition equivalent not in of RDB just only exists in condition.

How can I implement not in or is there an equivalent to not in?

like image 383
Minkyu Kim Avatar asked Mar 13 '23 11:03

Minkyu Kim


1 Answers

Here an implementation In PHP

public function getRecordsByInExpression($tableName, $providerCode, $fieldName, $values, $logicalOp = self::IN_EXP)
{
    $queryExp =[
        'TableName' => $tableName,
        'KeyConditionExpression' => 'ProviderCode = :pc',
        'FilterExpression' => $logicalOp == self::IN_EXP ? "$fieldName IN (:list)" : "NOT ($fieldName IN (:list))",
        'ExpressionAttributeValues' => [
            ':pc' => $providerCode,
            ':list' => implode(',', $values)
        ]
    ];

    return $this->query($queryExp)->get('Items');
}

At the end a NOT IN = NOT (field IN (:list))

like image 181
Sr. Libre Avatar answered Mar 23 '23 23:03

Sr. Libre