Reputation: 168
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.
Upvotes: 0
Views: 129
Reputation: 421
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.
Upvotes: 0
Reputation: 168
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="] },
})
Upvotes: 0
Reputation: 12359
Unfortunately, in this case, you have to scan the whole table. DDB is not optimized for this type of operation.
Upvotes: 1