首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有全局索引的DynamoDB查询

没有全局索引的DynamoDB查询
EN

Stack Overflow用户
提问于 2017-11-23 18:35:12
回答 1查看 174关注 0票数 0

我在我的DynamoDB中有一个简单的表,我想做一个简单的查询,只是一个status = active的列表

代码语言:javascript
复制
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中处理这个问题呢--把所有属性放在全局索引中?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-23 20:38:36

你在找扫描特征

在DynamoDB中,如果您有一个大型数据集(因为在返回所需内容之前,它会读取整个数据集。),则不建议这样做。

您可能希望在所有数据都可用的情况下执行复合排序键:

cpf_otherValue_otherValue2_...

也许不是全部,但使用最多的2/3和对begins_with Query.html#DDB-Query-request-KeyConditionExpression的查询

或者,如果您有高级搜索功能,最好是拥有一个ElasticSearch集群而不是DynamoDB : DynamoDB是一个支持大数据集和高吞吐量的键/值存储,高级搜索功能不是一个常见的用例:但是,如果您没有太多的数据,它也可以工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47461643

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档