Vladimir Venegas Vladimir Venegas - 14 days ago 6
Node.js Question

dynamodb: query with hash key only

I have this table:


  • DomainId string HashKey

  • EmailId string RangeKey



I was wondering if it's possible query this table with HashKey only, like this:

var AWS = require("aws-sdk");
var client = new AWS.DynamoDB.DocumentClient();
var dm = 'infodinamica.cl';

//Set params
var params = {
TableName : 'table-name',
KeyConditionExpression: "DomainId = :dm",
ExpressionAttributeValues: {
":dm": dm
},
Select: 'COUNT'
};

client.query(params, (err, data) => {
if(err)
console.log(JSON.stringify(err, null, 2));
else
console.log(JSON.stringify(data, null, 2));
}


ps: note that this table has HashKey and RangeKey.

Answer

Yes, it is possible to query the data using Hash Key only using query API.

Use the KeyConditionExpression parameter to provide a specific value for the partition key. The Query operation will return all of the items from the table or index with that partition key value. You can optionally narrow the scope of the Query operation by specifying a sort key value and a comparison operator in KeyConditionExpression. You can use the ScanIndexForward parameter to get results in forward or reverse order, by sort key.

Comments