我在我的DynamoDB中有一个简单的表,我想做一个简单的查询,只是一个status = active的列表
const AWS = require('aws-sdk');
const config = require('../../../../config/dynamo');
const { URI } = config;
AWS.config.update({
region: 'us-east-1'
});
const dynamodb = new AWS.DynamoDB({
endpoint: new AWS.Endpoint(URI)
});
const params = {
AttributeDefinitions: [{
AttributeName: 'idPhysicalPerson',
AttributeType: 'N'
},
{
AttributeName: 'cpf',
AttributeType: 'S'
}],
KeySchema: [{
AttributeName: 'idPhysicalPerson',
KeyType: 'HASH'
},
{
AttributeName: 'cpf',
KeyType: 'RANGE'
}],
ProvisionedThroughput: {
ReadCapacityUnits: 5,
WriteCapacityUnits: 5
},
TableName: 'PhysicalPerson'
};
dynamodb.createTable(params, (err, data) => {
if (err) {
console.log(err, err.stack);
} else {
console.log(data);
}
});这个表包含了很多属性,如果我想执行一个简单的查询,我总是需要将这些字段放在全局索引中吗?
我只想获取所有具有active状态的数据,但是在一个实际的应用程序中,如果我有一个像advanced filter这样的特性,可以设置很多属性,那么如何在DynamoDB中处理这个问题呢--把所有属性放在全局索引中?
发布于 2017-11-23 20:38:36
你在找扫描特征。
在DynamoDB中,如果您有一个大型数据集(因为在返回所需内容之前,它会读取整个数据集。),则不建议这样做。
您可能希望在所有数据都可用的情况下执行复合排序键:
cpf_otherValue_otherValue2_...
也许不是全部,但使用最多的2/3和对begins_with Query.html#DDB-Query-request-KeyConditionExpression的查询
或者,如果您有高级搜索功能,最好是拥有一个ElasticSearch集群而不是DynamoDB : DynamoDB是一个支持大数据集和高吞吐量的键/值存储,高级搜索功能不是一个常见的用例:但是,如果您没有太多的数据,它也可以工作。
https://stackoverflow.com/questions/47461643
复制相似问题