Biswajit Maharana
Biswajit Maharana

Reputation: 609

DynamoDB FilterExpression with 'NOT EXIST' as a condition boto3

I'm trying to perform a dynamodb table scan with some filter expression. Current filter expression has a condition of begins_with something like :

import os
import boto3
from boto3.dynamodb.conditions import Attr

env_id = os.environ['ENVIRONMENT']
buId   = '10014'

# Define the table
table = boto3.resource('dynamodb').Table(env_id+'-abcd')

response = table.scan(
    ProjectionExpression='#SubsId,#ItemId,#SeqNum',
    ExpressionAttributeNames={
        '#SubsId' : 'SubsId', # partition key
        '#ItemId' : 'ItemId', # sort key
        '#SeqNum' : 'SeqNum'  # sequence number
    },
    FilterExpression=Attr('SubsId').begins_with(buId) AND //SeqNum Not Exists
)

In the FilterExpression I want to check if

SeqNum Not Exists

Can someone help me with how can I add that after AND condition on the above code?

Upvotes: 0

Views: 6150

Answers (1)

hoangdv
hoangdv

Reputation: 16127

You can use '&' for AND and '|' for OR (doc). Your filter expression will look like this:

FilterExpression=Attr('SubsId').begins_with(buId) & Attr('SeqNum').not_exists()

Ref: Attr(name).not_exists()

Upvotes: 4

Related Questions