4

For suppose the item is like

{
'EventType': 'git/push'
'EventTime': 1416251010,
'Commits': [
    {
        'id': '29d02aff...',
        'subject': 'Add the thing to the place'
    },
    {
        'id': '9d888fec...',
        'subject': 'Spelling errors'
    },
    ...
]

}

then I want the output like

{
'EventType': 'git/push'
'EventTime': 1416251010,
'Commits': [
    {
        'id': '29d02aff...',
        'subject': 'Add the thing to the place'
    }
 ]
}

can you please suggest me the DynamoDB filter. Thanks in advance.

4
  • what are the attributes you would like to search with ? Commented Nov 2, 2017 at 13:30
  • Thanks notionquest for responding this post, I want to filter with EventType and subject from comments, actually, comments will contain more than one recode with the same subject, that is the case I want all the records with the matched subject. Commented Nov 3, 2017 at 5:32
  • If you know both the id and subject of the comments, then it is possible. Otherwise, it is not possible. Commented Nov 3, 2017 at 5:59
  • ok if I know id and subject how can I apply the filter condition Commented Nov 3, 2017 at 6:22

1 Answer 1

4

CONTAINS function can be used to filter or find the data in DynamoDB list. However, please note that you need to have both the attributes (i.e. id and subject) of the object (complex object in terms of DynamoDB) to find the data in List.

CONTAINS is supported for lists: When evaluating "a CONTAINS b", "a" can be a list; however, "b" cannot be a set, a map, or a list.

Sample code:-

var table = "eventtype";
var params = {
    TableName: table,
    KeyConditionExpression: "EventType = :eventType",
    FilterExpression: "contains(Commits, :commitVal )",
    ExpressionAttributeValues: {
        ":eventType": 'git/push',
        ":commitVal": {
            'id': '29d02aff',
            'subject': 'Add the thing to the place'
        }
    }
};

docClient.query(params, function (err, data) {
    if (err) {
        console.error("Unable to read item. Error JSON:", JSON.stringify(err,
            null, 2));
    } else {
        console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
    }
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer, Is it possible only with id.? in some situations I'm only known id I don't know a subject.
@Ram did you find a way to just check with id and not subject? I have a similar situation. Thanks!!
@RamMohan222, is there a way to get it with just ID?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.