简体   繁体   English

dynamodb:仅使用哈希键查询

[英]dynamodb: query with hash key only

I have this table: 我有这张桌子:

  • DomainId string HashKey DomainId字符串HashKey
  • EmailId string RangeKey EmailId字符串RangeKey

I was wondering if it's possible query this table with HashKey only, like this: 我想知道是否有可能仅使用HashKey查询此表,如下所示:

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. ps:请注意,此表具有HashKey和RangeKey。

Yes, it is possible to query the data using Hash Key only using query API . 是的,仅可以使用query API使用哈希键query API

Use the KeyConditionExpression parameter to provide a specific value for the partition key. 使用KeyConditionExpression参数为分区键提供特定的值。 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. 您可以选择通过在KeyConditionExpression中指定排序键值和比较运算符来缩小Query操作的范围。 You can use the ScanIndexForward parameter to get results in forward or reverse order, by sort key. 您可以使用ScanIndexForward参数通过排序键以正向或反向顺序获取结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM