Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 848
Vladimir Venegas Avatar asked Nov 19 '16 21:11

Vladimir Venegas


1 Answers

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.

like image 56
notionquest Avatar answered Sep 16 '22 16:09

notionquest