dynamodb - scan items where map contains a key

Viewed 12412

I have a table that contains a field (not a key field), called appsMap, and it looks like this:

appsMap = { "qa-app": "abc", "another-app": "xyz" }

I want to scan all rows whose appsMap contains the key "qa-app" (the value is not important, just the key). I tried something like this but it doesn't work in the way I need:

    FilterExpression = '#appsMap.#app <> :v',
    ExpressionAttributeNames = {
        "#app": "qa-app",
        "#appsMap": "appsMap"
    },
    ExpressionAttributeValues = {
        ":v": { "NULL": True }
    },
    ProjectionExpression  = "deviceID"

What's the correct syntax?

Thanks.

3 Answers

If I understand the question correctly, you can do the following:

FilterExpression = 'attribute_exists(#0.#1)',
ExpressionAttributeNames = {
    "#0": "appsMap",
    "#1": "qa-app"
},
ProjectionExpression  = "deviceID"
Related