- Newest
- Most votes
- Most comments
Based on your recent comment, this code will return you only the list of PK's for your table:
Using Scan you will read each item in the table. ProjectionExpression
tells DynamoDB only to return attributes which match that value, in your case id
.
var params = {
TableName : 'TableName',
ProjectionExpression: 'id'
};
documentClient.scan(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
});
Its not clear what you are looking for here.
I'm going to base this on the assumption that you want to get all the attributes which is stored for a given id
with id
being your partition key?
You should use Query which will target a single Item Collection and be much more efficient than a Scan which reads all the items in the table.
var params = {
TableName: 'TableName',
KeyConditionExpression: 'Id = :id',
ExpressionAttributeValues: {
':id': '123456'
}
};
documentClient.query(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
});
Furthermore, if you do not have a SortKey on your table, you can also use GetItem as each item will have a unique ID
:
var params = {
TableName : 'TableName',
Key: {
id: '123456'
}
};
documentClient.get(params, function(err, data) {
if (err) console.log(err);
else console.log(data);
});
Thanks for your reply, Like in ExpressionAttributeValues you are passing '123456' for comparison I don't want comparison I just need to fetch all values in a list or array of ID column which is type of partition key @LeeroyHannigan
Relevant content
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated a month ago
Thanks a lot
I guess I am basically asking the same question here: https://repost.aws/questions/QUOUXPjz5iTzWnd4FUl5_GEw/how-to-handle-an-access-pattern-in-which-you-need-to-list-values-of-all-partions-with-some-userid-pk. One difference though, this seems way too inefficient. For each partition you are going to consume a read-request. In my question, I am asking whether there is a better way of doing it than that; a way that will consume less read-requests.