如何在DynamoDB上创建本地具有GlobalSecondaryIndex的表

How create a table on DynamoDB with a GlobalSecondaryIndexes in local?

本文关键字:GlobalSecondaryIndex 的表 创建 DynamoDB      更新时间:2023-09-26

I DynamoDB在Windows 7上本地安装。我的项目是Node.js(0.12.0),我使用aws-sdk。

DynamoDB版本:2012-08-10

这项工作->

dynamodb.createTable({
TableName: 'Users',
AttributeDefinitions: [{AttributeName: 'userId', AttributeType: 'S'}],
KeySchema: [{AttributeName: 'userId', KeyType: 'HASH'}],
ProvisionedThroughput: {
    'ReadCapacityUnits': 5,
    'WriteCapacityUnits': 5
}
}, function () {
    ...
});

这不起作用->

dynamodb.createTable({
TableName: 'Users',
AttributeDefinitions: [{AttributeName: 'userId', AttributeType: 'S'}],
KeySchema: [{AttributeName: 'userId', KeyType: 'HASH'}],
ProvisionedThroughput: {
    'ReadCapacityUnits': 5,
    'WriteCapacityUnits': 5
},
GlobalSecondaryIndexes: [
    {
        IndexName: 'longitudeUserIndex',
        KeySchema: [
            {
                AttributeName: 'userId',
                KeyType: 'HASH'
            },
            {
                AttributeName: 'longitude',
                KeyType: 'RANGE'
            }
        ],
        Projection: {
            NonKeyAttributes: [
            ],
            ProjectionType: 'KEYS_ONLY'
        },
        ProvisionedThroughput: {
            'ReadCapacityUnits': 5,
            'WriteCapacityUnits': 5
        }
    }
]
}, function () {
    ...
});

Doc DynamoDB Javascript:http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/DynamoDB.html#createTable-属性

我解决了我的问题。

我添加了AttributeDefinitions经度。

AttributeDefinitions: [{AttributeName: 'userId', AttributeType: 'S'}, {AttributeName: 'longitude', AttributeType: 'N'}]
相关文章:
  • 没有找到相关文章