3

I am trying to fetch items, which satisfies certain conditions, from dynamodb

Here is the Item JSON structure.

    {
 "userID": "3201054407a58",
 "createdDate": 1643769000000,
 "modifiedDate": 1643769000000,
 "attributes": {
  "zipCode": "683562",
  "country": "India",
  "deleteFlag": "1"
 }
}

Partition key: userID Sort key: createdDate

I would like to filter results based on deleteFlag. ie; if deleteFlag not equal to 1, it should appear on result set.

The query I am using is as given below.

let params = {
        "TableName": 'user',
        KeyConditionExpression: "#uid = :id AND createdDate BETWEEN :minDate AND :maxDate",
        FilterExpression: '#deleteFlag <> :deleteFlag'
        ExpressionAttributeValues: {
            ':id': uuid,
            ':minDate': from,
            ':maxDate': to,
            ':deleteFlag': "1"
        },
        ExpressionAttributeNames: {
            '#uid': 'userID',
            '#deleteFlag': 'attributes.deleteFlag'
        }
    };

But, above filter is not working. How to filter based on deleteFlag.

Please help on this.

Jacob Nelson
  • 2,370
  • 23
  • 35
  • 3
    The problem is with the [dot] in `'#deleteFlag': 'attributes.deleteFlag'`. See https://stackoverflow.com/a/70262341/1103511 for the easy fix. – fedonev Jan 08 '22 at 09:16

0 Answers0