0

In DB there is an attribute (name "user_ids") in form of an array that contains user-id [a, b, c, d...]. I want to search that whole array using a single user-id.

3 Answers 3

1

Unfortunately, in this case, you have to scan the whole table. DDB is not optimized for this type of operation.

Sign up to request clarification or add additional context in comments.

Comments

0

var params = {
    TableName: 'my-table-name',
    FilterExpression: "#users = :id",
    ExpressionAttributeNames: {
        "#users": "users"
    },
    ExpressionAttributeValues: {
        ":id": ["KwV-yfctBcwCHIw="] // user-id
    }
};


dynamo.scan(params, (err, data) => {
    if (err) console.error({ err });

    console.log(data); // output -> { 'room-id': 'group-2', link: 'asdf', users: ["KwV-yfctBcwCHIw=", "Kqc-wfctacwCsww=", "lqw-yfftBcwqwIw="] },
})

Comments

0

yes you can do this using filterexpression, it's depends how you are storing the data . either it's "Document Types" (List/Map) or it's Sets,just give a try to filterexpression

you could refer initial aws documentation or there refer ton of example available online.

please refer this link... have some sample code.

Comments

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.