1
votes

I am using amazon dynamodb, lambda and api gateway services. I have a table in dynamodb call photo-group and it's Primary key is pid and other data such ownerid, photosrc,photosize etc.

I know how to use scan to get the data like:

   var data = JSON.stringify({
            "operation":'list',
            "TableName":"photo-group",
            "FilterExpression": "ownerid = :val)",
            "ExpressionAttributeValues": {":val": user}
});

But now I try to limit the result to get only 30 items by adding "Limit:30". I found that scan will scan the first 30 rows for me and not return 30 items to me. May I know how to filter 30 items by ownerid?

Thank you so much!

1
DynamoDB doesn't work this way. If you want query on specific field, it needs to have an index and you need to perform a query on it. Scan is literally going row by row. - adamkonrad
Thank you kixorz~ I added index for my table and I can query it now. But one important thing is that it needs extra cost for indexing...oops - TimLee

1 Answers

1
votes

You will need to either add an index on the values so you can query against an index or make multiple scan calls. Either of these solutions will have costs associate with them.